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
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 and you are on .NET Core 2.1-3.1, 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 eitherfalse
or 0.
These configuration options are not available starting with .NET 5.
Constructors
SocketsHttpHandler() |
Creates an instance of a SocketsHttpHandler class. |
Properties
AllowAutoRedirect |
Gets or sets a value that indicates whether the handler should follow redirection responses. |
AutomaticDecompression |
Gets or sets the type of decompression method used by the handler for automatic decompression of the HTTP content response. |
ConnectCallback |
Gets or sets a custom callback used to open new connections. |
ConnectTimeout |
Gets or sets the timespan to wait before the connection establishing times out. |
CookieContainer |
Gets or sets the managed cookie container object. |
Credentials |
Gets or sets authentication information used by this handler. |
DefaultProxyCredentials |
When the default (system) proxy is used, gets or sets the credentials used to submit to the default proxy server for authentication. |
EnableMultipleHttp2Connections |
Gets or sets a value that indicates whether additional HTTP/2 connections can be established to the same server when the maximum number of concurrent streams is reached on all existing connections. |
Expect100ContinueTimeout |
Gets or sets the time-out value for server HTTP 100 Continue response. |
IsSupported |
Gets a value that indicates whether the handler is supported on the current platform. |
KeepAlivePingDelay |
Gets or sets the keep alive ping delay. |
KeepAlivePingPolicy |
Gets or sets the keep alive ping behaviour. |
KeepAlivePingTimeout |
Gets or sets the keep alive ping timeout. |
MaxAutomaticRedirections |
Gets or sets the maximum number of allowed HTTP redirects. |
MaxConnectionsPerServer |
Gets or sets the maximum number of simultaneous TCP connections allowed to a single server. |
MaxResponseDrainSize |
Gets or sets the maximum amount of data that can be drained from responses in bytes. |
MaxResponseHeadersLength |
Gets or sets the maximum length, in kilobytes (1024 bytes), of the response headers. |
PlaintextStreamFilter | |
PooledConnectionIdleTimeout |
Gets or sets how long a connection can be idle in the pool to be considered reusable. |
PooledConnectionLifetime |
Gets or sets how long a connection can be in the pool to be considered reusable. |
PreAuthenticate |
Gets or sets a value that indicates whether the handler sends an Authorization header with the request. |
Properties | |
Proxy |
Gets or sets the custom proxy when the UseProxy property is |
RequestHeaderEncodingSelector |
Gets or sets a callback that decodes request headers values. |
ResponseDrainTimeout |
Gets or sets the timespan to wait for data to be drained from responses. |
ResponseHeaderEncodingSelector |
Gets or sets a callback that decodes response headers values. |
SslOptions |
Gets or sets the set of options used for client TLS authentication. |
UseCookies |
Gets or sets a value that indicates whether the handler should use cookies. |
UseProxy |
Gets or sets a value that indicates whether the handler should use a proxy. |
Methods
Dispose() |
Releases the unmanaged resources and disposes of the managed resources used by the HttpMessageHandler. (Inherited from HttpMessageHandler) |
Dispose(Boolean) |
Releases the unmanaged resources used by the HttpMessageHandler and optionally disposes of the managed resources. (Inherited from HttpMessageHandler) |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
GetHashCode() |
Serves as the default hash function. (Inherited from Object) |
GetType() |
Gets the Type of the current instance. (Inherited from Object) |
MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
Send(HttpRequestMessage, CancellationToken) |
When overridden in a derived class, sends an HTTP request with the specified request and cancellation token. Otherwise, throws a NotSupportedException. (Inherited from HttpMessageHandler) |
SendAsync(HttpRequestMessage, CancellationToken) |
Send an HTTP request as an asynchronous operation. (Inherited from HttpMessageHandler) |
ToString() |
Returns a string that represents the current object. (Inherited from Object) |