簡體   English   中英

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都適用。

嘗試了不同的方法,但所有方法均無濟於事:

  • 直接加載HTTPS版本(“ https://www.bestbuy.com ”)
  • 刪除對UserAgent,AutomaticDecompression和SecurityProtocol設置程序的調用

HttpClient類也會阻塞並以該資源的超時結束。

在Fiddler中,響應迅速返回,但看起來很奇怪-它是完全空的: 提琴手百思買

即時通訊10 rep缺少評論,這個答案應該在哪里,所以請不要拒絕投票,我只是想知道,您是否嘗試期望:100-繼續? 至少會延遲將您的回復分散為兩次回報,可能會告訴您更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM