The default message handler used by HttpClient in .NET Framework and .NET Core 2.0 and earlier.
public ref class HttpClientHandler : System::Net::Http::HttpMessageHandler
public class HttpClientHandler : System.Net.Http.HttpMessageHandler
type HttpClientHandler = class
inherit HttpMessageHandler
Public Class HttpClientHandler
Inherits HttpMessageHandler
static async Task 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();
client.Dispose();
}
For more information about this API, see Supplemental API remarks for HttpClientHandler.
Constructors Properties AllowAutoRedirectGets or sets a value that indicates whether the handler should follow redirection responses.
AutomaticDecompressionGets or sets the type of decompression method used by the handler for automatic decompression of the HTTP content response.
CheckCertificateRevocationListGets or sets a value that indicates whether the certificate is checked against the certificate authority revocation list.
ClientCertificateOptionsGets 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.
ClientCertificatesGets the collection of security certificates that are associated with requests to the server.
CookieContainerGets or sets the cookie container used to store server cookies by the handler.
CredentialsGets or sets authentication information used by this handler.
DangerousAcceptAnyServerCertificateValidatorGets a cached delegate that always returns true
.
When the default (system) proxy is being used, gets or sets the credentials to submit to the default proxy server for authentication. The default proxy is used only when UseProxy is set to true
and Proxy is set to null
.
Gets or sets the maximum number of redirects that the handler follows.
MaxConnectionsPerServerGets or sets the maximum number of concurrent connections (per server endpoint) allowed when making requests using an HttpClient object. Note that the limit is per server endpoint, so for example a value of 256 would permit 256 concurrent connections to http://www.adatum.com/ and another 256 to http://www.adventure-works.com/.
MaxRequestContentBufferSizeGets or sets the maximum request content buffer size used by the handler.
MaxResponseHeadersLengthGets or sets the maximum length, in kilobytes (1024 bytes), of the response headers. For example, if the value is 64, then 65536 bytes are allowed for the maximum response headers' length.
MeterFactoryGets or sets the IMeterFactory to create a custom Meter for the HttpClientHandler instance.
PreAuthenticateGets or sets a value that indicates whether the handler sends an Authorization header with the request.
PropertiesGets a writable dictionary (that is, a map) of custom properties for the HttpClient requests. The dictionary is initialized empty; you can insert and query key-value pairs for your custom handlers and special processing.
ProxyGets or sets proxy information used by the handler.
ServerCertificateCustomValidationCallbackGets or sets a callback method to validate the server certificate.
SslProtocolsGets or sets the TLS/SSL protocols used by the HttpClient objects managed by the HttpClientHandler object.
SupportsAutomaticDecompressionGets a value that indicates whether the handler supports automatic response content decompression.
SupportsProxyGets a value that indicates whether the handler supports proxy settings.
SupportsRedirectConfigurationGets a value that indicates whether the handler supports configuration settings for the AllowAutoRedirect and MaxAutomaticRedirections properties.
UseCookiesGets or sets a value that indicates whether the handler uses the CookieContainer property to store server cookies and uses these cookies when sending requests.
UseDefaultCredentialsGets or sets a value that controls whether default credentials are sent with requests by the handler.
UseProxyGets or sets a value that indicates whether the handler uses a proxy for requests.
Methods See alsoCollaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide. In this articleWas this page helpful?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4