![](/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.