WinHttpHandler WinHttpHandler WinHttpHandler WinHttpHandler Class


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.

public ref class WinHttpHandler : System::Net::Http::HttpMessageHandler
public class WinHttpHandler : System.Net.Http.HttpMessageHandler
type WinHttpHandler = class
    inherit HttpMessageHandler
Public Class WinHttpHandler
Inherits HttpMessageHandler


WinHttpHandler 是类似于其他现有类,如HttpClientHandlerWinHttpHandler is similar to other existing classes such as HttpClientHandler. WinHttpHandler 提供下的一个处理程序HttpClient实例并用于向服务器发出 HTTP 请求和接收服务器响应。WinHttpHandler provides a handler underneath an HttpClient instance and is used to send HTTP requests out to a server and receive server responses.

WinHttpHandler 旨在由 ASP.NET Core 和其他与 HTTP 服务器通信的.NET 应用程序主要在服务器环境中使用。WinHttpHandler is designed to be used primarily in server environments by ASP.NET Core and other .NET applications that communicate with HTTP servers. WinHttpHandler 此外为开发人员提供更精细地控制应用程序的 HTTP 通信比HttpClientHandler类。WinHttpHandler also provides developers with more granular control over the application's HTTP communication than the HttpClientHandler class. 这允许开发人员能够实现更高级的 HTTP 方案或修改系统默认值 (例如,代理设置,超时和服务器 SSL 证书验证)。This allows developers to implement more advanced HTTP scenarios or modify system defaults (for example, proxy settings, timeouts and server SSL certificate validation).

WinHttpHandler 不是替代HttpClientHandler,它是更高级的版本为方案提供其中HttpClientHandler不足以开发人员。WinHttpHandler is not intended to be a replacement for HttpClientHandler, it is a more advanced version provided for scenarios where HttpClientHandler is insufficient for developers. WinHttpHandler 作为 Windows 的 WinHTTP 接口上的瘦包装器实现,仅支持在 Windows 系统上。WinHttpHandler is implemented as a thin wrapper on the WinHTTP interface of Windows and is only supported on Windows systems.

当使用多个处理程序链WinHttpHandler应在链的底部。When using a chain of multiple handlers, WinHttpHandler should be at the bottom of the chain.


WinHttpHandler() WinHttpHandler() WinHttpHandler() WinHttpHandler()

初始化 WinHttpHandler 类的新实例。Initializes a new instance of the WinHttpHandler class.


AutomaticDecompression AutomaticDecompression AutomaticDecompression AutomaticDecompression

获取或设置处理程序用于自动解压缩 HTTP 内容响应的解压缩方法类型。Gets or sets the type of decompression method used by the handler for automatic decompression of the HTTP content response.

AutomaticRedirection AutomaticRedirection AutomaticRedirection AutomaticRedirection

获取或设置一个值,该值指示处理程序是否应跟随 HTTP 重定向响应。Gets or sets a value that indicates whether the handler should follow HTTP redirection responses.

CheckCertificateRevocationList CheckCertificateRevocationList CheckCertificateRevocationList CheckCertificateRevocationList

获取或设置一个值,该值指示是否在 SSL 证书验证过程中检查证书吊销列表。Gets or sets a value that indicates whether to check the revocation list of certificates during SSL certificate validation.

ClientCertificateOption ClientCertificateOption ClientCertificateOption ClientCertificateOption

获取或设置一个值,该值指示是否从证书存储自动挑选证书,或者是否允许调用方通过特定的客户端证书。Gets or sets a value that indicates if the certificate is automatically picked from the certificate store or if the caller is allowed to pass in a specific client certificate.

ClientCertificates ClientCertificates ClientCertificates ClientCertificates

获取或设置客户端身份验证 SSL 证书的集合,在 ClientCertificateOption 属性设置为 Manual 时,处理程序将该集合用于客户端身份验证。Gets or sets a collection of client authentication SSL certificates that are used for client authentication by the Handler if the ClientCertificateOption property is set to Manual.

CookieContainer CookieContainer CookieContainer CookieContainer

获取或设置托管 cookie 容器对象。Gets or sets the managed cookie container object. 仅当 CookieUsePolicy 属性设置为 UseSpecifiedCookieContainer 时才使用此属性。This property is only used when the CookieUsePolicy property is set to UseSpecifiedCookieContainer. 否则,SendAsync(HttpRequestMessage, CancellationToken) 方法会引发异常。Otherwise, the SendAsync(HttpRequestMessage, CancellationToken) method will throw an exception.

CookieUsePolicy CookieUsePolicy CookieUsePolicy CookieUsePolicy

获取或设置一个值,该值指示应如何管理和使用 cookie。Gets or sets a value that indicates how cookies should be managed and used. 开发者可以选择忽略 cookie、允许处理程序自动管理 cookie 或使用 CookieContainer 对象手动处理 cookie。Developers can choose to ignore cookies, allow the handler to automatically manage them or manually handle them using a CookieContainer object.

DefaultProxyCredentials DefaultProxyCredentials DefaultProxyCredentials DefaultProxyCredentials

获取或设置用于向身份验证代理证实用户身份的凭据。Gets or sets the credentials used to authenticate the user to an authenticating proxy.

MaxAutomaticRedirections MaxAutomaticRedirections MaxAutomaticRedirections MaxAutomaticRedirections

获取或设置允许的最大 HTTP 重定向数。Gets or sets the maximum number of allowed HTTP redirects.

MaxConnectionsPerServer MaxConnectionsPerServer MaxConnectionsPerServer MaxConnectionsPerServer

获取或设置允许向单个服务器连接的最大 TCP 连接数。Gets or sets the maximum number of TCP connections allowed to a single server.

MaxResponseDrainSize MaxResponseDrainSize MaxResponseDrainSize MaxResponseDrainSize

获取或设置可从响应中排出的最大数据量(以字节为单位)。Gets or sets the maximum amount of data that can be drained from responses in bytes.

MaxResponseHeadersLength MaxResponseHeadersLength MaxResponseHeadersLength MaxResponseHeadersLength

获取或设置服务器响应中标头部分的最大大小(以字节为单位)。Gets or sets the maximum size of the header portion from the server response in bytes.

PreAuthenticate PreAuthenticate PreAuthenticate PreAuthenticate

获取或设置一个值,该值指示处理程序是否随请求发送授权标头。Gets or sets a value that indicates whether the handler sends an Authorization header with the request.

Properties Properties Properties Properties
Proxy Proxy Proxy Proxy

获取或设置当 WindowsProxyUsePolicy 属性设置为使用自定义代理时的自定义代理。Gets or sets the custom proxy when the WindowsProxyUsePolicy property is set to use a custom proxy.

ReceiveDataTimeout ReceiveDataTimeout ReceiveDataTimeout ReceiveDataTimeout

获取或设置从服务器接收响应的数据部分的超时值。Gets or sets the timeout for receiving the data portion of a response from the server.

ReceiveHeadersTimeout ReceiveHeadersTimeout ReceiveHeadersTimeout ReceiveHeadersTimeout

获取或设置从服务器接收响应的标头的超时值。Gets or sets the timeout for receiving the headers of a response from the server.

SendTimeout SendTimeout SendTimeout SendTimeout

获取或设置发送请求的超时值。Gets or sets the timeout for sending a request.

ServerCertificateValidationCallback ServerCertificateValidationCallback ServerCertificateValidationCallback ServerCertificateValidationCallback

获取或设置用于验证服务器证书的回调方法。Gets or sets a callback method to validate the server certificate. 此回叫是 SSL 握手的一部分。This callback is part of the SSL handshake.

ServerCredentials ServerCredentials ServerCredentials ServerCredentials

获取或设置客户端用于向服务器进行身份验证的凭据。Gets or sets the credentials to be used by the client to authenticate to the server.

SslProtocols SslProtocols SslProtocols SslProtocols

获取或设置客户端支持的 TLS/SSL 协议的集合。Gets or sets the collection of TLS/SSL protocols supported by the client.

WindowsProxyUsePolicy WindowsProxyUsePolicy WindowsProxyUsePolicy WindowsProxyUsePolicy

获取或设置代理设置。Gets or sets the proxy setting. 此属性可设置为禁用代理、使用自定义代理或在计算机上使用 WinHTTP 或 WinInet 的代理设置。This property can be set to disable the proxy, use a custom proxy, or use the proxy settings of WinHTTP or WinInet on the machine.


Dispose() Dispose() Dispose() Dispose()

释放由 HttpMessageHandler 使用的非托管资源和托管资源。Releases the unmanaged resources and disposes of the managed resources used by the HttpMessageHandler.

(Inherited from HttpMessageHandler)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
SendAsync(HttpRequestMessage, CancellationToken) SendAsync(HttpRequestMessage, CancellationToken) SendAsync(HttpRequestMessage, CancellationToken) SendAsync(HttpRequestMessage, CancellationToken)

以异步操作发送 HTTP 请求。Sends an HTTP request as an asynchronous operation.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)