HttpClientHandler Class

.NET Framework (current version)
 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

The default message handler used by HttpClient.

Namespace:   System.Net.Http
Assembly:  System.Net.Http (in System.Net.Http.dll)

System.Object
  System.Net.Http.HttpMessageHandler
    System.Net.Http.HttpClientHandler
      System.Net.Http.WebRequestHandler

type HttpClientHandler = 
    class
        inherit HttpMessageHandler
    end

NameDescription
System_CAPS_pubmethodHttpClientHandler()

Creates an instance of a HttpClientHandler class.

NameDescription
System_CAPS_pubpropertyAllowAutoRedirect

Gets or sets a value that indicates whether the handler should follow redirection responses.

System_CAPS_pubpropertyAutomaticDecompression

Gets or sets the type of decompression method used by the handler for automatic decompression of the HTTP content response.

System_CAPS_pubpropertyCheckCertificateRevocationList

Gets or sets a value that indicates whether the certificate is checked against the certificate authority revocation list.

System_CAPS_pubpropertyClientCertificateOptions

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.

System_CAPS_pubpropertyClientCertificates

Gets the maximum allowed length of the response headers.

System_CAPS_pubpropertyCookieContainer

Gets or sets the cookie container used to store server cookies by the handler.

System_CAPS_pubpropertyCredentials

Gets or sets authentication information used by this handler.

System_CAPS_pubpropertyDefaultProxyCredentials

Gets or sets the credentials to submit to the proxy server for authentication.

System_CAPS_pubpropertyMaxAutomaticRedirections

Gets or sets the maximum number of redirects that the handler follows.

System_CAPS_pubpropertyMaxConnectionsPerServer

Gets or sets the maximum number of concurrent connections allowed by an HttpClient object.

System_CAPS_pubpropertyMaxRequestContentBufferSize

Gets or sets the maximum request content buffer size used by the handler.

System_CAPS_pubpropertyMaxResponseHeadersLength

Gets or sets the maxiumum response header length.

System_CAPS_pubpropertyPreAuthenticate

Gets or sets a value that indicates whether the handler sends an Authorization header with the request.

System_CAPS_pubpropertyProperties

Gets a set of properties for the all HttpClient requests.

System_CAPS_pubpropertyProxy

Gets or sets proxy information used by the handler.

System_CAPS_pubpropertyServerCertificateCustomValidationCallback

Gets or sets a callback method to validate the server certificate.

System_CAPS_pubpropertySslProtocols

Gets or sets the SSL protocol used by the HttpClient objects managed by the HttpClientHandler object.

System_CAPS_pubpropertySupportsAutomaticDecompression

Gets a value that indicates whether the handler supports automatic response content decompression.

System_CAPS_pubpropertySupportsProxy

Gets a value that indicates whether the handler supports proxy settings.

System_CAPS_pubpropertySupportsRedirectConfiguration

Gets a value that indicates whether the handler supports configuration settings for the AllowAutoRedirect and MaxAutomaticRedirections properties.

System_CAPS_pubpropertyUseCookies

Gets or sets a value that indicates whether the handler uses the CookieContainer property to store server cookies and uses these cookies when sending requests.

System_CAPS_pubpropertyUseDefaultCredentials

Gets or sets a value that controls whether default credentials are sent with requests by the handler.

System_CAPS_pubpropertyUseProxy

Gets or sets a value that indicates whether the handler uses a proxy for requests.

NameDescription
System_CAPS_pubmethodDispose()

Releases the unmanaged resources and disposes of the managed resources used by the HttpMessageHandler.(Inherited from HttpMessageHandler.)

System_CAPS_protmethodDispose(Boolean)

Releases the unmanaged resources used by the HttpClientHandler and optionally disposes of the managed resources.(Overrides HttpMessageHandler.Dispose(Boolean).)

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodSendAsync(HttpRequestMessage, CancellationToken)

Creates an instance of HttpResponseMessage based on the information provided in the HttpRequestMessage as an operation that will not block.(Overrides HttpMessageHandler.SendAsync(HttpRequestMessage, CancellationToken).)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

The HttpClientHandler class and classes derived from it enable developers to configure a variety of options ranging from proxies to authentication.

 static async void Main()
{
    // Create an HttpClientHandler object and set to use default credentials
    HttpClientHandler handler = new HttpClientHandler();
    handler.UseDefaultCredentials = true;

    // Create an HttpClient object
    HttpClient client = new HttpClient(handler);

    // Call asynchronous network methods in a try/catch block to handle exceptions
    try	
    {
       HttpResponseMessage response = await client.GetAsync("http://www.contoso.com/");

       response.EnsureSuccessStatusCode();

       string responseBody = await response.Content.ReadAsStringAsync();
       Console.WriteLine(responseBody);
     }  
     catch(HttpRequestException e)
     {
        Console.WriteLine("\nException Caught!");	
        Console.WriteLine("Message :{0} ",e.Message);
     }

     // Need to call dispose on the HttpClient and HttpClientHandler objects 
     // when done using them, so the app doesn't leak resources
     handler.Dispose(true);
     client.Dispose(true);
 }

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.5
Portable Class Library
Supported in: portable .NET platforms
Windows Phone
Available since 8.1

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: