xiamo23
V2EX  ›  C#

.NET6 HttpClient 无反应也不超时?

  •  
  •   xiamo23 · Dec 25, 2023 · 3631 views
    This topic created in 911 days ago, the information mentioned may be changed or developed.

    这个代码哪里有问题吗?请求后一直无反应,也不会报超时,但是抓包软件已经看到正常请求和返回了?是不是 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 replies    2023-12-27 10:13:05 +08:00
    zhzhwcn
        1
    zhzhwcn  
       Dec 26, 2023
    HttpResponseMessage response = await webclient.GetAsync(urls[0]).ConfigureAwait(false);

    试试
    xiamo23
        2
    xiamo23  
    OP
       Dec 26, 2023
    @zhzhwcn 可以了,感谢答复。能说说原理吗?
    xiamo23
        4
    xiamo23  
    OP
       Dec 27, 2023
    @zhzhwcn 感谢答复。。原来是死锁了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2930 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 14:53 · PVG 22:53 · LAX 07:53 · JFK 10:53
    ♥ Do have faith in what you're doing.