考虑以下 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);
}
fiddle :https://dotnetfiddle.net/M7NZgG
相同的代码适用于大多数其他 URL。
尝试了不同的东西,但都没有帮助:
HttpClient 类也因该资源的超时而卡住并结束。
在 Fiddler 中,响应很快被返回,但看起来很奇怪——它完全是空的:
最佳答案
我没有评论 10 个代表,这个答案应该在哪里,所以请不要投反对票,我只是想知道,你是否尝试过期望:100-继续?至少它会延迟将您的回复分成两个返回,可能会告诉您更多信息。
关于c# - HttpWebRequest.GetResponse 方法卡住特定的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52426004/