SocketsHttpHandler 類別

定義

提供 .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
繼承
SocketsHttpHandler

備註

從 .NET Core 2.1 開始,SocketsHttpHandler 類別提供較高層級 HTTP 網路類別(例如 HttpClient)所使用的實作為。Starting 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 和適用于 Linux 的 .NET Core 相關。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)
    
  • 藉由定義netcore. .runtimeconfig.json. json設定檔中的 System.Net.Http.UseSocketsHttpHandler 參數: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()

屬性

AllowAutoRedirect
AutomaticDecompression

取得或設定解壓縮方法的類型,此為 HTTP 內容回應的自動解壓縮處理常式所使用。Gets or sets the type of decompression method used by the handler for automatic decompression of the HTTP content response.

ConnectTimeout
CookieContainer

取得或設定受管理的 Cookie 容器物件。Gets or sets the managed cookie container object.

Credentials
DefaultProxyCredentials

在使用預設 (系統) Proxy 時,取得或設定用來提交到預設 Proxy 伺服器進行驗證的認證。When the default (system) proxy is used, gets or sets the credentials used to submit to the default proxy server for authentication.

Expect100ContinueTimeout
MaxAutomaticRedirections

取得或設定允許的 HTTP 重新導向的數目上限。Gets or sets the maximum number of allowed HTTP redirects.

MaxConnectionsPerServer

取得或設定單一伺服器允許的同時 TCP 連線數目上限。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

取得或設定回應標頭的最大長度,以 KB (1024 位元組) 為單位。Gets or sets the maximum length, in kilobytes (1024 bytes), of the response headers.

PooledConnectionIdleTimeout

取得或設定集區中的連線須閒置多久時間,才會視為可重複使用。Gets or sets how long a connection can be idle in the pool to be considered reusable.

PooledConnectionLifetime
PreAuthenticate

取得或設定值,這個值指出處理常式是否隨著要求傳送授權標頭。Gets or sets a value that indicates whether the handler sends an Authorization header with the request.

Properties
Proxy

在 UseProxy 屬性為 true 時,取得或設定自訂 Proxy。Gets or sets the custom proxy when the UseProxy property is true.

ResponseDrainTimeout
SslOptions

取得或設定一組用於用戶端 TLS 驗證的選項。Gets or sets the set of options used for client TLS authentication.

UseCookies
UseProxy

方法

Dispose()

釋放 Unmanaged 資源,並處置 HttpMessageHandler 所使用的 Managed 資源。Releases the unmanaged resources and disposes of the managed resources used by the HttpMessageHandler.

(繼承來源 HttpMessageHandler)
Dispose(Boolean)

釋放 HttpMessageHandler 所使用的 Unmanaged 資源,並選擇性處置 Managed 資源。Releases the unmanaged resources used by the HttpMessageHandler and optionally disposes of the managed resources.

(繼承來源 HttpMessageHandler)
Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

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

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
SendAsync(HttpRequestMessage, CancellationToken)

以非同步作業的方式,傳送 HTTP 要求。Send an HTTP request as an asynchronous operation.

(繼承來源 HttpMessageHandler)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於