SocketsHttpHandler SocketsHttpHandler SocketsHttpHandler SocketsHttpHandler Class

定義

提供 .NET Core 2.1 及更新版本中 HttpClient 使用的預設訊息處理常式。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
繼承
SocketsHttpHandlerSocketsHttpHandlerSocketsHttpHandlerSocketsHttpHandler

備註

.NET Core 2.1 中,從開始SocketsHttpHandler類別會提供這類使用較高層級的 HTTP 網路類別的實作HttpClientStarting with .NET Core 2.1, the SocketsHttpHandler class provides the implementation used by higher-level HTTP networking classes such as HttpClient. 使用SocketsHttpHandler提供許多優點: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. 比方說,libcurl不再適用於 macOS 和.NET Core 的相依性 .NET Core for Linux。For example, libcurl is no longer a dependency on .NET Core for macOS and .NET Core for Linux.

  • 跨所有.NET 平台的一致行為。Consistent behavior across all .NET platforms.

如果不需要這項變更,您可以設定您的應用程式使用較舊System.Net.Http.HttpClientHandler數種類別: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:

  • 藉由呼叫AppContext.SetSwitch方法,如下所示:By calling the AppContext.SetSwitch method as follows:

    AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);
    
    AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", False)
    
  • 藉由定義System.Net.Http.UseSocketsHttpHandler切換移入 。 netcore.runtimeconfig.json組態檔:By defining the System.Net.Http.UseSocketsHttpHandler switch in the .netcore.runtimeconfig.json configuration file:

    "runtimeOptions": {
      "configProperties": {
          "System.Net.Http.UseSocketsHttpHandler": false
      }
    }
    
  • 定義名為環境變數DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER並將它設定為false則為 0。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()

釋放 Unmanaged 資源,並處置 HttpMessageHandler 所使用的 Managed 資源。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)

釋放 HttpMessageHandler 所使用的 Unmanaged 資源,並選擇性處置 Managed 資源。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()

取得目前執行個體的 TypeGets the Type of the current instance.

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

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

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

以非同步作業的方式,傳送 HTTP 要求。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)

適用於