c# - HttpWebRequest.GetResponse 方法卡住特定的 url

标签 c# httpwebrequest dotnet-httpclient

考虑以下 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。

尝试了不同的东西,但都没有帮助:
  • 直接加载 HTTPS 版本(“https://www.bestbuy.com”)
  • 删除对 UserAgent、AutomaticDecompression 和 SecurityProtocol setter 的调用

  • HttpClient 类也因该资源的超时而卡住并结束。

    在 Fiddler 中,响应很快被返回,但看起来很奇怪——它完全是空的:
    Fiddler bestbuy

    最佳答案

    我没有评论 10 个代表,这个答案应该在哪里,所以请不要投反对票,我只是想知道,你是否尝试过期望:100-继续?至少它会延迟将您的回复分成两个返回,可能会告诉您更多信息。

    关于c# - HttpWebRequest.GetResponse 方法卡住特定的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52426004/

    相关文章:

    c# - 编译器错误消息 CS1061,但我已经定义了我的事件处理程序 ASP.net/C#

    c# - 单元测试中 Web Api Controller 的 ContentResult 始终返回 null

    c# - 跟踪 HTTPWebRequest 的进度

    iphone - 如何检查 iPhone 中是否使用 dataWithContentsOfURL 加载了图像?

    c# - HttpWebRequest 结果为 “The request was aborted: Could not create SSL/TLS secure channel” 并返回 code=AlgorithmMismatch

    c# - HttpClient : Correct order to detect encoding

    c# - 从 C# 调用托管 C++ 函数

    c# - 如何模拟持有 CrossFilePicker 的异步方法?

    c# - 解析不同的HttpClient

    c# - 通用应用程序缺少 WriteableBitmap SaveJpeg