![](/img/trans.png)
[英]Which specific status codes cause a WebException to be thrown by HttpWebRequest.GetResponse()?
[英]HttpWebRequest.GetResponse method stucks for specific urls
考虑以下URL:“ http://www.bestbuy.com ”。 此资源可以在所有浏览器中以及从所有位置快速正确地加载。
但是,当前该URL的基本C#代码卡住了(对于任何超时,超时都结束了):
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var req = WebRequest.CreateHttp("http://www.bestbuy.com");
req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
req.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36";
req.Timeout = 30000; // you can set any timeout
using (var resp = (HttpWebResponse)req.GetResponse()) // stucks and finally ends by timeout here
{
Console.WriteLine(resp.StatusCode);
Console.WriteLine(resp.ResponseUri.AbsoluteUri);
}
小提琴: https : //dotnetfiddle.net/M7NZgG
相同的代码对大多数其他URL都适用。
尝试了不同的方法,但所有方法均无济于事:
HttpClient类也会阻塞并以该资源的超时结束。
即时通讯10 rep缺少评论,这个答案应该在哪里,所以请不要拒绝投票,我只是想知道,您是否尝试期望:100-继续? 至少会延迟将您的回复分散为两次回报,可能会告诉您更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.