3

HttpClient class with in .NET core is not using keep-alives. It is re-connecting and re-authenticating to server on each request. This can be especially slow with NTLM authentication that requires multiple round-trips.

I'm passing new HttpClientHandler() to HttpClient constructor.

In .NET 4, I could use WebRequestHandler that has keep-alive capabilities, but this class seems to be missing in .NET Core.

Is there a way to enable keep-alives for HttpClient in .NET Core?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
alex
  • 12,464
  • 3
  • 46
  • 67
  • Are you seeing an explicit header to turn keep-alive off? It is the default in HTTP 1.1 – Leonardo Herrera Mar 02 '16 at 16:45
  • I intercept traffic using Fiddler proxy and see that for each request new connection is established and authentication handshake is repeated. There are also no keep-alive headers sent to server. For older .Net applications based on .Net 4.5, I can see that there is a single established connection that is re-used. – alex Mar 02 '16 at 19:08
  • 1
    NTLM does not allow connection re-use by default. https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.unsafeauthenticatedconnectionsharing(v=vs.110).aspx – Tratcher Mar 04 '16 at 00:36

0 Answers0