Remote server (403) Forbidden error while using WebClient

前端 未结 2 548
独厮守ぢ
独厮守ぢ 2020-12-21 01:23

I am trying to query some URL using WebClient.

I have a collection which I loop through to get the QueryString value, and build final URL,

相关标签:
2条回答
  • 2020-12-21 02:12

    If everything you said is correct, then I suspect server throttling is playing a part. Try adding a Thread.Sleep in your loop to slow things down.

    0 讨论(0)
  • 2020-12-21 02:23

    Some web servers can block requests based on the user agent string they provide. In your case, you send an empty string as a user agent. Try to add the user agent of a browser, any browser would be fine.

    For example:

    client.Headers.Add("user-agent", " Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0");
    

    For a list of user agents, you can click here.

    0 讨论(0)
提交回复
热议问题