Uredi

Deli z drugimi prek


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
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public sealed class SocketsHttpHandler : System.Net.Http.HttpMessageHandler
public sealed class SocketsHttpHandler : System.Net.Http.HttpMessageHandler
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
type SocketsHttpHandler = class
    inherit HttpMessageHandler
type SocketsHttpHandler = class
    inherit HttpMessageHandler
Public NotInheritable Class SocketsHttpHandler
Inherits HttpMessageHandler
Inheritance
SocketsHttpHandler
Attributes

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 either false or 0.

These configuration options are not available starting with .NET 5.

Constructors

SocketsHttpHandler()

Creates an instance of a SocketsHttpHandler class.

Properties

ActivityHeadersPropagator

Gets or sets the propagator to use when propagating the distributed trace and context. Use null to disable propagation.

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.

EnableMultipleHttp3Connections

Gets or sets a value that indicates whether additional HTTP/3 connections can be established to the same server.

Expect100ContinueTimeout

Gets or sets the time-out value for server HTTP 100 Continue response.

InitialHttp2StreamWindowSize

Defines the initial HTTP2 stream receive window size for all connections opened by the this SocketsHttpHandler.

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.

MeterFactory

Gets or sets the IMeterFactory to create a custom Meter for the SocketsHttpHandler instance.

PlaintextStreamFilter

Gets or sets a custom callback that provides access to the plaintext HTTP protocol stream.

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

Gets a writable dictionary (that is, a map) of custom properties for the HttpClient requests. The dictionary is initialized empty; you can insert and query key-value pairs for your custom handlers and special processing.

Proxy

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

RequestHeaderEncodingSelector

Gets or sets a callback that selects the Encoding to encode request header values.

ResponseDrainTimeout

Gets or sets the timespan to wait for data to be drained from responses.

ResponseHeaderEncodingSelector

Gets or sets a callback that selects the Encoding to decode response header 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)

Applies to