System.Net.Http 命名空間

提供現代 HTTP 應用程式的程式設計介面。 Provides a programming interface for modern HTTP applications.

類別

ByteArrayContent

提供以位元組陣列為基礎的 HTTP 內容。Provides HTTP content based on a byte array.

CFNetworkHandler
DelegatingHandler

HTTP 處理常式的類型,這些處理常式會將 HTTP 回應訊息的處理委派給另一個處理常式,也稱為內部處理常式。A type for HTTP handlers that delegate the processing of HTTP response messages to another handler, called the inner handler.

FormUrlEncodedContent

使用 application/x-www-form-urlencoded MIME 類型編碼之名稱/值 Tuple 的容器。A container for name/value tuples encoded using application/x-www-form-urlencoded MIME type.

HttpClient

提供基底類別,用來傳送 HTTP 要求,以及從 URI 所識別的資源接收 HTTP 回應。Provides a base class for sending HTTP requests and receiving HTTP responses from a resource identified by a URI.

HttpClientFactoryExtensions

IHttpClientFactory 的擴充方法。Extensions methods for IHttpClientFactory.

HttpClientHandler

.NET Framework 和 .NET Core 2.0 及更舊版本中 HttpClient 使用的預設訊息處理常式。The default message handler used by HttpClient in .NET Framework and .NET Core 2.0 and earlier.

HttpContent

代表 HTTP 實體內容和內容標頭的基底類別。A base class representing an HTTP entity body and content headers.

HttpMessageHandler

HTTP 訊息處理常式的基底類型。A base type for HTTP message handlers.

HttpMessageHandlerFactoryExtensions

IHttpMessageHandlerFactory 的擴充方法。Extensions methods for IHttpMessageHandlerFactory.

HttpMessageInvoker

特定類別,允許應用程式呼叫 HTTP 處理常式鏈結的 SendAsync(HttpRequestMessage, CancellationToken) 方法。A specialty class that allows applications to call the SendAsync(HttpRequestMessage, CancellationToken) method on an HTTP handler chain.

HttpMethod

協助程式類別,用於擷取和比較標準 HTTP 方法,以及建立新的 HTTP 方法。A helper class for retrieving and comparing standard HTTP methods and for creating new HTTP methods.

HttpRequestException

HttpClientHttpMessageHandler 類別所擲回之例外狀況的基底類別。A base class for exceptions thrown by the HttpClient and HttpMessageHandler classes.

HttpRequestMessage

代表 HTTP 要求訊息。Represents a HTTP request message.

HttpRequestOptions
HttpResponseMessage

表示包含狀態碼及資料的 HTTP 回應訊息。Represents a HTTP response message including the status code and data.

MessageProcessingHandler

處理常式的基底類型,這些處理常式僅對要求和 (或) 回應訊息執行一些小型處理。A base type for handlers which only do some small processing of request and/or response messages.

MultipartContent

提供使用 multipart/* 內容類型規格進行序列化之 HttpContent 物件的集合。Provides a collection of HttpContent objects that get serialized using the multipart/* content type specification.

MultipartFormDataContent

提供使用 multipart/form-data MIME 類型編碼內容的容器。Provides a container for content encoded using multipart/form-data MIME type.

NSUrlSessionHandler

在使用 Xamarin stack (iOS、macOS、watchOS、tvOS) 的 Apple 平台上,由  HttpClient  使用的預設訊息處理常式The default message handler used by HttpClient on Apple platforms using the Xamarin stack (iOS, macOS, watchOS, tvOS)

ReadOnlyMemoryContent

ReadOnlyMemory<T> 為基礎提供 HTTP 內容。Provides HTTP content based on a ReadOnlyMemory<T>.

RtcRequestFactory
SocketsHttpConnectionContext

代表傳遞給 SocketsHttpHandler 執行個體之 ConnectCallback 的內容。Represents the context passed to the ConnectCallback for a SocketsHttpHandler instance. .

SocketsHttpHandler

提供 .NET Core 2.1 及更新版本中 HttpClient 使用的預設訊息處理常式。Provides the default message handler used by HttpClient in .NET Core 2.1 and later.

SocketsHttpPlaintextStreamFilterContext
StreamContent

根據資料流提供 HTTP 內容。Provides HTTP content based on a stream.

StringContent

根據字串提供 HTTP 內容。Provides HTTP content based on a string.

WebRequestHandler

提供 Windows 市集應用程式或其他環境中所沒有的桌面特定功能。Provides desktop-specific features not available to Windows Store apps or other environments.

WinHttpHandler

依據 Windows 的 WinHTTP 介面處理訊息。Handles messages based on the WinHTTP interface of Windows. 此類別為伺服器環境而設計。This class is intended for use in server environments.

結構

HttpRequestOptionsKey<TValue>

介面

IHttpClientFactory

元件的 Factory 抽象概念,可以使用指定邏輯名稱的自訂組態來建立 HttpClient 執行個體。A factory abstraction for a component that can create HttpClient instances with custom configuration for a given logical name.

IHttpMessageHandlerFactory

元件的 Factory 抽象概念,可以使用指定邏輯名稱的自訂組態來建立 HttpMessageHandler 執行個體。A factory abstraction for a component that can create HttpMessageHandler instances with custom configuration for a given logical name.

列舉

ClientCertificateOption

指定如何提供用戶端憑證。Specifies how client certificates are provided.

CookieUsePolicy

這個列舉可讓您在與伺服器通訊時控制 HTTP Cookie。This enumeration allows control of HTTP cookies when communicating with the server.

HttpCompletionOption

表示 HttpClient 作業應該在取得回應之後立即視為已完成,或在讀取整個回應訊息 (包括內容) 之後視為已完成。Indicates if HttpClient operations should be considered completed either as soon as a response is available, or after reading the entire response message including the content.

HttpKeepAlivePingPolicy

指定透過閒置的連線傳送 HTTP/2 ping 框架的時機。Specifies when the HTTP/2 ping frame is sent on an idle connection.

HttpVersionPolicy

針對選取及協調要求的 HTTP 版本指定行為。Specifies behaviors for selecting and negotiating the HTTP version for a request.

WindowsProxyUsePolicy

此列舉會提供在 Windows 上執行時,HttpClient 用於 Proxy 設定的可用選項。This enumeration provides available options for the proxy settings used by an HttpClient when running on Windows.

委派

HeaderEncodingSelector<TContext>

代表會指定使用哪一種編碼來解譯標題值的方法。Represents a method that specifies the encoding to use when interpreting header values.

備註

System.Net.Http命名空間的設計目的是要提供下列各項:The System.Net.Http namespace is designed to provide the following:

  1. HTTP 用戶端元件,可讓使用者透過 HTTP 使用新式 web 服務。HTTP client components that allow users to consume modern web services over HTTP.

  2. 用戶端和伺服器都可使用的 HTTP 元件 (HTTP 標頭和訊息,例如) 。HTTP components that can be used by both clients and servers (HTTP headers and messages, for example). 這可在用戶端和伺服器端提供一致的程式設計模型,以透過 HTTP 進行新式 web 服務。This provides a consistent programming model on both the client and the server side for modern web services over HTTP.

System.Net.Http命名空間和相關的 System.Net.Http.Headers 命名空間提供下列一組元件:The System.Net.Http namespace and the related System.Net.Http.Headers namespace provide the following set of components:

  1. HttpClient -用來透過 HTTP 傳送和接收要求的主要類別。HttpClient - the primary class used to send and receive requests over HTTP.

  2. HttpRequestMessageHttpResponseMessage -HTTP 訊息,如同 IETF 在 RFC 2616 中所定義。HttpRequestMessage and HttpResponseMessage - HTTP messages as defined in RFC 2616 by the IETF.

  3. HttpHeaders -IETF 在 RFC 2616 中定義的 HTTP 標頭。HttpHeaders - HTTP headers as defined in RFC 2616 by the IETF.

  4. HttpClientHandler -負責產生 HTTP 回應訊息的 HTTP 處理常式。HttpClientHandler - HTTP handlers responsible for producing HTTP response messages.

您可以使用各種不同的 HTTP 訊息處理常式。There are various HTTP message handlers that can be used. 其中包括下列各項。These include the following.

  1. DelegatingHandler -用來將處理常式插入處理常式鏈的類別。DelegatingHandler - A class used to plug a handler into a handler chain.

  2. HttpMessageHandler -衍生自的簡單類別,可支援大部分應用程式的最常見需求。HttpMessageHandler - A simple to class to derive from that supports the most common requirements for most applications.

  3. HttpClientHandler -在處理常式鏈底部運作的類別,實際上會處理 HTTP 傳輸作業。HttpClientHandler - A class that operates at the bottom of the handler chain that actually handles the HTTP transport operations.

  4. WebRequestHandler -在處理常式鏈類別底部運作的特殊類別,此類別會處理 HTTP 傳輸作業與物件特定的選項 System.Net.HttpWebRequestWebRequestHandler - A specialty class that operates at the bottom of the handler chain class that handles HTTP transport operations with options that are specific to the System.Net.HttpWebRequest object.

HTTP 訊息的內容與 RFC 2616 中定義的實體主體相對應。The contents of an HTTP message corresponds to the entity body defined in RFC 2616.

有許多類別可用於 HTTP 內容。A number of classes can be used for HTTP content. 其中包括下列各項。These include the following.

  1. ByteArrayContent -以位元組陣列為基礎的 HTTP 內容。ByteArrayContent - HTTP content based on a byte array.

  2. FormUrlEncodedContent -使用 application/x-www 表單 urlencoded MIME 類型編碼之名稱/值元組的 HTTP 內容。FormUrlEncodedContent - HTTP content of name/value tuples encoded using application/x-www-form-urlencoded MIME type.

  3. MultipartContent -使用多部分/* 內容類型規格進行序列化的 HTTP 內容。MultipartContent - HTTP content that gets serialized using the multipart/* content type specification.

  4. MultipartFormDataContent -使用多部分/表單資料 MIME 類型編碼的 HTTP 內容。MultipartFormDataContent - HTTP content encoded using the multipart/form-data MIME type.

  5. StreamContent -以資料流程為基礎的 HTTP 內容。StreamContent - HTTP content based on a stream.

  6. StringContent -以字串為基礎的 HTTP 內容。StringContent - HTTP content based on a string.

如果使用 System.Net.Http 和命名空間的應用程式 System.Net.Http.Headers 想要下載大量資料 (50 mb 或以上的) ,則應用程式應該串流這些下載,而不使用預設的緩衝。If an app using the System.Net.Http and System.Net.Http.Headers namespaces intends to download large amounts of data (50 megabytes or more), then the app should stream those downloads and not use the default buffering. 如果使用預設緩衝,用戶端記憶體使用量將會變得非常大,可能會大幅降低效能。If the default buffering is used the client memory usage will get very large, potentially resulting in substantially reduced performance.

System.Net.Http和命名空間中的類別 System.Net.Http.Headers 可以用來開發 Windows Store 應用程式或桌面應用程式。Classes in the System.Net.Http and System.Net.Http.Headers namespaces can be used to develop Windows Store apps or desktop apps. 在 Windows Store 應用程式中使用時, System.Net.Http 和命名空間中的類別 System.Net.Http.Headers 會受到網路隔離功能的影響,這是所使用之應用程式安全性模型的一部分 Windows 8Windows 8When used in a Windows Store app, classes in the System.Net.Http and System.Net.Http.Headers namespaces are affected by network isolation feature, part of the application security model used by the Windows 8Windows 8. 您必須在適用于系統的 Windows Store 應用程式的應用程式資訊清單中啟用適當的網路功能,才能讓 Windows store 應用程式進行網路存取。The appropriate network capabilities must be enabled in the app manifest for a Windows Store app for the system to allow network access by a Windows store app. 如需詳細資訊,請參閱 Windows 市集應用程式的網路隔離For more information, see the Network Isolation for Windows Store Apps.

另請參閱