简体   繁体   中英

HttpWebRequest.GetResponse method stucks for specific urls

Consider the following 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:

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

The same code works fine for most other URLs.

Tried different things, but all of them did not help:

  • direct loading of HTTPS version (" https://www.bestbuy.com ")
  • remove calls for UserAgent, AutomaticDecompression and SecurityProtocol setters

HttpClient class also stucks and ends by timeout for that resource.

In Fiddler the response is quickly returned, but it looks strange - it is completely empty: 提琴手百思买

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? at the very least it will delay spread your response into two returns, possibly telling you more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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