简体   繁体   English

HttpWebRequest.GetResponse方法卡住了特定的网址

[英]HttpWebRequest.GetResponse method stucks for specific urls

Consider the following URL: " http://www.bestbuy.com ". 考虑以下URL:“ http://www.bestbuy.com ”。 This resource is quickly and correctly loaded in all browsers and from all locations. 此资源可以在所有浏览器中以及从所有位置快速正确地加载。

However, basic C# code currently stucks (ends by timeout for any timeout) for this URL: 但是,当前该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);
}

Fiddle: https://dotnetfiddle.net/M7NZgG 小提琴: https : //dotnetfiddle.net/M7NZgG

The same code works fine for most other URLs. 相同的代码对大多数其他URL都适用。

Tried different things, but all of them did not help: 尝试了不同的方法,但所有方法均无济于事:

  • direct loading of HTTPS version (" https://www.bestbuy.com ") 直接加载HTTPS版本(“ https://www.bestbuy.com ”)
  • remove calls for UserAgent, AutomaticDecompression and SecurityProtocol setters 删除对UserAgent,AutomaticDecompression和SecurityProtocol设置程序的调用

HttpClient class also stucks and ends by timeout for that resource. HttpClient类也会阻塞并以该资源的超时结束。

In Fiddler the response is quickly returned, but it looks strange - it is completely empty: 在Fiddler中,响应迅速返回,但看起来很奇怪-它是完全空的: 提琴手百思买

im 10 rep short of commenting, where this answer should be, so please dont down vote, i was just wondering, did you try expect:100-continue? 即时通讯10 rep缺少评论,这个答案应该在哪里,所以请不要拒绝投票,我只是想知道,您是否尝试期望:100-继续? at the very least it will delay spread your response into two returns, possibly telling you more info. 至少会延迟将您的回复分散为两次回报,可能会告诉您更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM