共用方式為


HttpClientHandler 類別

定義

這是 .NET Framework 中預設使用的 HttpClient 訊息處理程式。

public ref class HttpClientHandler : System::Net::Http::HttpMessageHandler
public class HttpClientHandler : System.Net.Http.HttpMessageHandler
type HttpClientHandler = class
    inherit HttpMessageHandler
Public Class HttpClientHandler
Inherits HttpMessageHandler
繼承
HttpClientHandler
衍生

範例

static async Task Main()
{
   // Create an HttpClientHandler object and set to use default credentials
   HttpClientHandler handler = new HttpClientHandler();
   handler.UseDefaultCredentials = true;

   // Create an HttpClient object
   HttpClient client = new HttpClient(handler);

   // Call asynchronous network methods in a try/catch block to handle exceptions
   try
   {
      HttpResponseMessage response = await client.GetAsync("http://www.contoso.com/");

      response.EnsureSuccessStatusCode();

      string responseBody = await response.Content.ReadAsStringAsync();
      Console.WriteLine(responseBody);
   }
   catch(HttpRequestException e)
   {
       Console.WriteLine("\nException Caught!");
       Console.WriteLine("Message :{0} ",e.Message);
   }

   // Need to call dispose on the HttpClient and HttpClientHandler objects
   // when done using them, so the app doesn't leak resources
   handler.Dispose();
   client.Dispose();
}

備註

欲了解更多關於此 API 的資訊,請參閱 HttpClientHandler 的補充 API 備註

建構函式

名稱 Description
HttpClientHandler()

建立一個類別的實例 HttpClientHandler

屬性

名稱 Description
AllowAutoRedirect

取得或設定一個值,指示處理器是否應該遵循重定向回應。

AutomaticDecompression

取得或設定處理程序用於自動解壓縮 HTTP 內容回應的解壓縮方法類型。

CheckCertificateRevocationList

取得或設定一個值,指示該憑證是否與憑證授權中心的撤銷清單進行檢查。

ClientCertificateOptions

會取得或設定一個值,指示憑證是自動從憑證庫中選取,還是呼叫者是否被允許傳遞特定客戶端憑證。

ClientCertificates

取得與伺服器請求相關的安全憑證集合。

CookieContainer

由處理器取得或設定用於儲存伺服器 cookie 的 cookie 容器。

Credentials

取得或設定此處理器使用的認證資訊。

DangerousAcceptAnyServerCertificateValidator

會獲得一個快取代理,且總是回傳 true

DefaultProxyCredentials

當使用預設(系統)代理時,會取得或設定憑證提交給預設代理伺服器進行驗證。 預設代理僅在 UseProxy 設定為 且 trueProxynull時使用。

MaxAutomaticRedirections

接收或設定處理器所遵循的最大重定向次數。

MaxConnectionsPerServer

在使用 HttpClient 物件發出請求時,取得或設定每個伺服器端點允許的最大同時連線數。 請注意,限制是針對每個伺服器端點,例如值為 256 會允許 256 個同時連線到 http://www.adatum.com/http://www.adventure-works.com/

MaxRequestContentBufferSize

取得或設定處理器使用的最大請求內容緩衝區大小。

MaxResponseHeadersLength

取得或設定回應標頭的最大長度(以千位元組為單位,1024 位元組)。 例如,若值為 64,則允許最大回應標頭長度為 65536 位元組。

MeterFactory

取得或設定 來IMeterFactory為該HttpClientHandler實例建立自訂Meter

PreAuthenticate

取得或設定一個值,指示處理器是否在請求中傳送授權標頭。

Properties

會獲得一個可寫入的字典(也就是一張映射),裡面有請求的 HttpClient 自訂屬性。 字典初始化為空;你可以插入並查詢自訂處理器和特殊處理的鍵值對。

Proxy

取得或設定處理者使用的代理資訊。

ServerCertificateCustomValidationCallback

取得或設定回調方法來驗證伺服器憑證。

SslProtocols

取得或設定由 HttpClient HttpClientHandler 物件管理的物件所使用的 TLS/SSL 協定。

SupportsAutomaticDecompression

會取得一個值,指示處理器是否支援自動回應內容解壓縮。

SupportsProxy

會得到一個值,表示處理器是否支援代理設定。

SupportsRedirectConfiguration

會取得一個值,表示處理器是否支援 和 MaxAutomaticRedirections 屬性的設定AllowAutoRedirect設定。

UseCookies

取得或設定一個值,指示處理器是否使用 CookieContainer 該屬性來儲存伺服器 Cookie,並在發送請求時使用這些 Cookie。

UseDefaultCredentials

取得或設定一個值,控制處理器是否會隨請求傳送預設憑證。

UseProxy

取得或設定一個值,指示處理器是否使用代理伺服器來處理請求。

方法

名稱 Description
Dispose()

釋放未管理的資源並處理由 HttpMessageHandler.

(繼承來源 HttpMessageHandler)
Dispose(Boolean)

釋放未管理的資源, HttpClientHandler 並可選擇性地處置這些受管理資源。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object的淺層複本。

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

根據 中提供的HttpRequestMessage資訊建立 的HttpResponseMessage實例。

SendAsync(HttpRequestMessage, CancellationToken)

根據所提供的HttpRequestMessage資訊建立一個HttpResponseMessage不會阻塞的操作實例。

ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

適用於

另請參閱