Connection keep-alive not working with System.Net.Http.HttpClient on certain hosts

后端 未结 2 1096
情书的邮戳
情书的邮戳 2020-12-18 01:43

I\'m experimenting with the Heroku API using the .NET System.Net.Http.HttpClient. In particular, I want keep-alive to work so that I can send many

相关标签:
2条回答
  • 2020-12-18 01:54

    Use WebRequestHandler class instead of HttpClientHandler and set property HttpWebRequest.UnsafeAuthenticatedConnectionSharing to True.

    0 讨论(0)
  • 2020-12-18 01:58

    Some proxy servers will ignore the keep-alive when doing their authentication. If I recall correctly it's when the proxy server uses NTLM authentication.

    In the past, I've had to add a partial class to "help" some web service proxy classes.

    I overrode the GetWebRequest(Uri uri) method with

    System.Net.HttpWebRequest webRequest = 
            (System.Net.HttpWebRequest)base.GetWebRequest(uri);
    webRequest.ProtocolVersion = HttpVersion.Veraion10;  // I know this is strange, but it works
    webRequest.ServicePoint.Expect100Continue = false;  // This is where the magic lives
    return webRequest;
    
    0 讨论(0)
提交回复
热议问题