SocketsHttpHandler SocketsHttpHandler SocketsHttpHandler SocketsHttpHandler Class


Provides the default message handler used by HttpClient in .NET Core 2.1 and later.

public ref class SocketsHttpHandler sealed : System::Net::Http::HttpMessageHandler
public sealed class SocketsHttpHandler : System.Net.Http.HttpMessageHandler
type SocketsHttpHandler = class
    inherit HttpMessageHandler
Public NotInheritable Class SocketsHttpHandler
Inherits HttpMessageHandler


Starting with .NET Core 2.1, the SocketsHttpHandler class provides the implementation used by higher-level HTTP networking classes such as HttpClient. The use of SocketsHttpHandler offers a number of advantages:

  • A significant performance improvement when compared with the previous implementation.

  • The elimination of platform dependencies, which simplifies deployment and servicing. For example, libcurl is no longer a dependency on .NET Core for macOS and .NET Core for Linux.

  • Consistent behavior across all .NET platforms.

If this change is undesirable, you can configure your application to use the older System.Net.Http.HttpClientHandler class instead in a number of ways:

  • By calling the AppContext.SetSwitch method as follows:

    AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);
    AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", False)
  • By defining the System.Net.Http.UseSocketsHttpHandler switch in the .netcore.runtimeconfig.json configuration file:

    "runtimeOptions": {
      "configProperties": {
          "System.Net.Http.UseSocketsHttpHandler": false
  • By defining an environment variable named DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER and setting it to either false or 0.


SocketsHttpHandler() SocketsHttpHandler() SocketsHttpHandler() SocketsHttpHandler()


AllowAutoRedirect AllowAutoRedirect AllowAutoRedirect AllowAutoRedirect
AutomaticDecompression AutomaticDecompression AutomaticDecompression AutomaticDecompression
ConnectTimeout ConnectTimeout ConnectTimeout ConnectTimeout
CookieContainer CookieContainer CookieContainer CookieContainer
Credentials Credentials Credentials Credentials
DefaultProxyCredentials DefaultProxyCredentials DefaultProxyCredentials DefaultProxyCredentials
Expect100ContinueTimeout Expect100ContinueTimeout Expect100ContinueTimeout Expect100ContinueTimeout
MaxAutomaticRedirections MaxAutomaticRedirections MaxAutomaticRedirections MaxAutomaticRedirections
MaxConnectionsPerServer MaxConnectionsPerServer MaxConnectionsPerServer MaxConnectionsPerServer
MaxResponseDrainSize MaxResponseDrainSize MaxResponseDrainSize MaxResponseDrainSize
MaxResponseHeadersLength MaxResponseHeadersLength MaxResponseHeadersLength MaxResponseHeadersLength
PooledConnectionIdleTimeout PooledConnectionIdleTimeout PooledConnectionIdleTimeout PooledConnectionIdleTimeout

Gets or sets how long a connection can be idle in the pool to be considered reusable.

PooledConnectionLifetime PooledConnectionLifetime PooledConnectionLifetime PooledConnectionLifetime
PreAuthenticate PreAuthenticate PreAuthenticate PreAuthenticate
Properties Properties Properties Properties
Proxy Proxy Proxy Proxy
ResponseDrainTimeout ResponseDrainTimeout ResponseDrainTimeout ResponseDrainTimeout
SslOptions SslOptions SslOptions SslOptions
UseCookies UseCookies UseCookies UseCookies
UseProxy UseProxy UseProxy UseProxy


Dispose() Dispose() Dispose() Dispose()

Releases the unmanaged resources and disposes of the managed resources used by the HttpMessageHandler.

(Inherited from HttpMessageHandler)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

Releases the unmanaged resources used by the HttpMessageHandler and optionally disposes of the managed resources.

(Inherited from HttpMessageHandler)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
SendAsync(HttpRequestMessage, CancellationToken) SendAsync(HttpRequestMessage, CancellationToken) SendAsync(HttpRequestMessage, CancellationToken) SendAsync(HttpRequestMessage, CancellationToken)

Send an HTTP request as an asynchronous operation.

(Inherited from HttpMessageHandler)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to