即使使用用户代理,file_get_contents 也禁止使用 403

时间:2021-07-27 17:34:15

标签: php web-scraping header file-get-contents

我正在使用此功能,即使在定义、用户代理和标题中的所有内容后,我仍收到禁止错误。

这是我的功能:

public class Database : IDisposable
{
    private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
    private readonly ThirdPartyDb thirdPartyDb = new ThirdPartyDb();
    private bool disposedValue;

    public string Get()
    {
        if (cancellationTokenSource.Token.IsCancellationRequested) return ""; //Return anything acceptable for you

        return thirdPartyDb.Get("foo");
    }

    protected virtual void Dispose(bool disposing)
    {
        if (!disposedValue)
        {
            if (disposing)
            {
                cancellationTokenSource.Cancel();
                thirdPartyDb.Dispose();
            }

            disposedValue = true;
        }
    }

    public void Dispose()
    {
        Dispose(disposing: true);
        GC.SuppressFinalize(this);
    }
}

0 个答案:

没有答案
相关问题