SocketsHttpHandler SocketsHttpHandler SocketsHttpHandler SocketsHttpHandler Class

Definition

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
Inheritance
SocketsHttpHandlerSocketsHttpHandlerSocketsHttpHandlerSocketsHttpHandler

Remarks

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.

Constructors

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

Properties

AllowAutoRedirect AllowAutoRedirect AllowAutoRedirect AllowAutoRedirect
AutomaticDecompression AutomaticDecompression AutomaticDecompression AutomaticDecompression

Gets or sets the type of decompression method used by the handler for automatic decompression of the HTTP content response.

ConnectTimeout ConnectTimeout ConnectTimeout ConnectTimeout
CookieContainer CookieContainer CookieContainer CookieContainer

Gets or sets the managed cookie container object.

Credentials Credentials Credentials Credentials
DefaultProxyCredentials DefaultProxyCredentials DefaultProxyCredentials DefaultProxyCredentials

When the default (system) proxy is used, gets or sets the credentials used to submit to the default proxy server for authentication.

Expect100ContinueTimeout Expect100ContinueTimeout Expect100ContinueTimeout Expect100ContinueTimeout
MaxAutomaticRedirections MaxAutomaticRedirections MaxAutomaticRedirections MaxAutomaticRedirections

Gets or sets the maximum number of allowed HTTP redirects.

MaxConnectionsPerServer MaxConnectionsPerServer MaxConnectionsPerServer MaxConnectionsPerServer

Gets or sets the maximum number of simultaneous TCP connections allowed to a single server.

MaxResponseDrainSize MaxResponseDrainSize MaxResponseDrainSize MaxResponseDrainSize

Gets or sets the maximum amount of data that can be drained from responses in bytes.

MaxResponseHeadersLength MaxResponseHeadersLength MaxResponseHeadersLength MaxResponseHeadersLength

Gets or sets the maximum length, in kilobytes (1024 bytes), of the response headers.

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

Gets or sets a value that indicates whether the handler sends an Authorization header with the request.

Properties Properties Properties Properties
Proxy Proxy Proxy Proxy

Gets or sets the custom proxy when the UseProxy property is true.

ResponseDrainTimeout ResponseDrainTimeout ResponseDrainTimeout ResponseDrainTimeout
SslOptions SslOptions SslOptions SslOptions

Gets or sets the set of options used for client TLS authentication.

UseCookies UseCookies UseCookies UseCookies
UseProxy UseProxy UseProxy UseProxy

Methods

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