我所要做的就是创建一个程序,从耐克即将推出的鞋的页面上获得一个网络响应,但是我总是遇到一个错误,说这是被禁止的。关于这个话题的其他帖子对我来说都没有用,有什么我可以做的吗,或者我只是搞砸了?代码如下:
WebRequest request = WebRequest.Create("https://www.nike.com/launch/?s=upcoming");
WebResponse response = request.GetResponse();这就是错误:
System.Net.WebException: 'The remote server returned an error: (403) Forbidden.'发布于 2019-02-23 13:39:20
看起来像是标题问题,试试这个:
WebClient client = new WebClient();
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
client.Headers.Add("Content-Type", "application / zip, application / octet - stream");
client.Headers.Add("Referer", "http://whatevs");
client.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
String someStuff = client.DownloadString("https://www.hassanhabib.com");
Console.WriteLine(someStuff);
Console.Read();删除了Accept-Encoding行,现在应该可以了。
https://stackoverflow.com/questions/54838297
复制相似问题