V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xiamo23
V2EX  ›  C#

.NET6 HttpClient 无反应也不超时?

  •  
  •   xiamo23 · 124 天前 · 947 次点击
    这是一个创建于 124 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这个代码哪里有问题吗?请求后一直无反应,也不会报超时,但是抓包软件已经看到正常请求和返回了?是不是 HOST 和请求 URI 不一直的问题》?? var handler = new HttpClientHandler { AllowAutoRedirect = false, CookieContainer = new CookieContainer(), UseCookies = true, UseProxy = true, Proxy = new WebProxy("http://127.0.0.1:8888", false), ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }, MaxAutomaticRedirections = 1,

    }; using HttpClient webclient = new(handler); webclient.DefaultRequestVersion = HttpVersion.Version20; webclient.Timeout = TimeSpan.FromSeconds(10);

    webclient.DefaultRequestHeaders.Host = urls[1]; webclient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", ua(mobile)); webclient.DefaultRequestHeaders.TryAddWithoutValidation("x-requested-with", "com.ct.client"); webclient.DefaultRequestHeaders.TryAddWithoutValidation("upgrade-insecure-requests", "1"); HttpResponseMessage response = await webclient.GetAsync(urls[0]); 然后就一直没反应了

    4 条回复    2023-12-27 10:13:05 +08:00
    zhzhwcn
        1
    zhzhwcn  
       123 天前
    HttpResponseMessage response = await webclient.GetAsync(urls[0]).ConfigureAwait(false);

    试试
    xiamo23
        2
    xiamo23  
    OP
       123 天前
    @zhzhwcn 可以了,感谢答复。能说说原理吗?
    xiamo23
        4
    xiamo23  
    OP
       122 天前
    @zhzhwcn 感谢答复。。原来是死锁了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   917 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 22:30 · PVG 06:30 · LAX 15:30 · JFK 18:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.