2 回答

TA貢獻1785條經(jīng)驗 獲得超4個贊
出于某種原因,它不喜歡提供的用戶代理。如果您省略設置UserAgent一切正常
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("https://it.gearbest.com/tv-box/pp_009940949913.html");
request.Credentials = CredentialCache.DefaultCredentials;
//request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36";
request.ContentType = "text/html; charset=UTF-8";
另一種解決方案是設置request.Connection為隨機字符串(但不是keep-aliveor close)
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36";
request.Connection = "random value";
它也有效,但我無法解釋原因。

TA貢獻2065條經(jīng)驗 獲得超14個贊
也許值得嘗試一下...
HttpRequest.KeepAlive = false;
HttpRequest.ProtocolVersion = HttpVersion.Version10;
- 2 回答
- 0 關注
- 132 瀏覽
添加回答
舉報