System.Net.Http Namespace

System.Net.Http 命名空间提供用于现代 HTTP 应用程序的编程接口。 The System.Net.Http namespace provides a programming interface for modern HTTP applications.

Classes

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 类型编码的名称/值元组的容器。 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.

HttpClientHandler

HttpClient 使用的默认消息处理程序。 The default message handler used by HttpClient.

HttpContent

表示 HTTP 实体正文和内容标头的基类。 A base class representing an HTTP entity body and content headers.

HttpMessageHandler

HTTP 消息处理程序的基类。 A base type for HTTP message handlers.

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

提供 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
ReadOnlyMemoryContent
RtcRequestFactory
SocketsHttpHandler
StreamContent

提供基于流的 HTTP 内容。 Provides HTTP content based on a stream.

StringContent

提供基于字符串的 HTTP 内容。 Provides HTTP content based on a string.

WebRequestHandler

提供不可用于 Windows Store 应用程序或其他环境的特定以桌面的功能。 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.WinHttpHandler For more information about installing this class for use in Desktop apps, see System.Net.Http.WinHttpHandler.

Enums

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 所使用的代理设置的可用选项。 This enumeration provides available options for the proxy settings used by an HttpClient when running on Windows.

Remarks

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 的在底部的实际处理的 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 类型编码的名称/值元组的 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 的使用 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 兆字节或多个),则该应用程序应流式传输这些下载并使用默认缓冲。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 Store 应用的网络隔离For more information, see the Network Isolation for Windows Store Apps.