System.Net.Http 命名空間

System.Net.Http命名空間提供現代 HTTP 應用程式的程式設計介面。 The System.Net.Http namespace 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.

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

提供使用多重/表單資料 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
RtcRequestFactory
SocketsHttpHandler

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

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

WinHttpHandler 是以 Windows 的 WinHTTP 介面為基礎的特殊訊息處理常式,預定在伺服器環境中使用。WinHttpHandler is a specialty message handler based on the WinHTTP interface of Windows and is intended for use in server environments. 透過將這個類別安裝為 NuGet 封裝,其也可用於桌面應用程式。This class is also available for use in Desktop apps by installing it as a NuGet package. 如需安裝這個類別以用於桌面應用程式的詳細資訊,請參閱 System.Net.Http.WinHttpHandlerFor more information about installing this class for use in Desktop apps, see System.Net.Http.WinHttpHandler.

介面

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.

WindowsProxyUsePolicy

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

備註

System.Net.Http命名空間可提供下列:The System.Net.Http namespace is designed to provide the following:

  1. 允許使用者透過 HTTP 使用新式 web 服務的 HTTP 用戶端元件。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). 這提供一致的程式設計模型用戶端和伺服器端上的新式 web 服務透過 HTTP。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 -HTTP 標頭由 IETF RFC 2616 中所定義。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 handles 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 -A 底部是什麼在處理 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.HttpWebRequest物件。WebRequestHandler - 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 使用應用程式/x-www-表單-urlencoded MIME 類型編碼的名稱/值 tuple 的 HTTP 內容。FormUrlEncodedContent - HTTP content of name/value tuples encoded using application/x-www-form-urlencoded MIME type.

  3. MultipartContent HTTP 內容取得序列化使用 multipart / * 內容類型規格。MultipartContent - HTTP content that gets serialized using the multipart/* content type specification.

  4. MultipartFormDataContent 為使用 multipart/form-data 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.HttpSystem.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.HttpSystem.Net.Http.Headers命名空間可以用來開發 Windows 市集應用程式或傳統型應用程式。Classes in the System.Net.Http and System.Net.Http.Headers namespaces can be used to develop Windows Store apps or desktop apps. 中的 Windows 市集應用程式中使用時,類別System.Net.HttpSystem.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 市集應用程式的 Windows 市集應用程式的應用程式資訊清單中。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.

另請參閱