2 回答
TA贡献1785条经验 获得超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条经验 获得超13个赞
也许值得尝试一下...
HttpRequest.KeepAlive = false;
HttpRequest.ProtocolVersion = HttpVersion.Version10;
- 2 回答
- 0 关注
- 104 浏览
添加回答
举报