HttpClientHandler Class

Namespace: System.Net.Http

Provides a base class for sending HTTP requests and receiving HTTP responses from a resource identified by a URI. This class is intended to be used with the HttpClient class.

Syntax

public class HttpClientHandler : HttpMessageHandler

Inheritance

Remarks

The HttpClientHandler class provides the default implementation for sending HTTP requests. It handles details such as connection management, cookie handling, and authentication. When you create an instance of HttpClient, it uses an instance of HttpClientHandler by default.

You can configure the behavior of the HTTP request pipeline by customizing the properties of the HttpClientHandler. For example, you can control cookie handling, proxy settings, SSL/TLS validation, and timeouts.

If you need more advanced control over the HTTP request and response process, you can create a custom HttpMessageHandler that inherits from HttpClientHandler or implements the HttpMessageHandler interface directly.

Properties

Name Description
AllowAutoRedirect Gets or sets a value that indicates whether the HTTP handler follows HTTP redirects.
AutomaticDecompression Gets or sets the decompression methods that the handler should support.
ClientCertificateOptions Gets or sets a value that specifies how client certificates are sent to the server.
CookieContainer Gets or sets the container that holds cookies.
Credentials Gets or sets the network credentials for the request.
MaxAutomaticRedirections Gets or sets the maximum number of automatic redirections.
MaxHttpVersion Gets or sets the maximum HTTP protocol version that the handler will use.
PreAuthenticate Gets or sets a value that indicates whether the handler sends authentication information on the first request.
Proxy Gets or sets the proxy used to send requests.
SslProtocols Gets or sets the SSL/TLS protocols that are used to authenticate the server.
UseCookies Gets or sets a value that indicates whether the handler uses cookies.
UseProxy Gets or sets a value that indicates whether the handler uses a proxy.

Methods

Name Description
Dispose() Releases the unmanaged resources used by the HttpClientHandler and optionally releases the managed resources.
SendAsync(HttpRequestMessage, CancellationToken) Sends an HTTP request to the specified Uri and obtains the response.

Events

This class does not have events.

See Also