HttpClient Class

Provides a base class for sending HTTP requests and receiving HTTP responses from a resource identified by a URI.

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

public ref class HttpClient : public HttpMessageInvoker

The HttpClient type exposes the following members.

  NameDescription
Public methodHttpClient()Initializes a new instance of the HttpClient class.
Public methodHttpClient(HttpMessageHandler)Initializes a new instance of the HttpClient class with a specific handler.
Public methodHttpClient(HttpMessageHandler, Boolean)Initializes a new instance of the HttpClient class with a specific handler and a value that indicates whether this instance is responsible for disposing the handler.
Top

  NameDescription
Public propertyBaseAddressGets or sets the base address of Uniform Resource Identifier (URI) of the Internet resource used when sending requests.
Public propertyDefaultRequestHeadersGets the headers which should be sent with each request.
Public propertyMaxResponseContentBufferSizeGets or sets the maximum number of bytes to buffer when reading the response content.
Public propertyTimeoutGets or sets the number of milliseconds to wait before the request times out.
Top

  NameDescription
Public methodCancelPendingRequestsCancel all pending requests on this instance.
Public methodDeleteAsync(String)Sends a DELETE request to the specified Uri as an asynchronous operation.
Public methodDeleteAsync(Uri)Sends a DELETE request to the specified Uri as an asynchronous operation.
Public methodDeleteAsync(String, CancellationToken)Sends a DELETE request to the specified Uri with a cancellation token as an asynchronous operation.
Public methodDeleteAsync(Uri, CancellationToken)Sends a DELETE request to the specified Uri with a cancellation token as an asynchronous operation.
Public methodDispose()Releases the unmanaged resources and disposes of the managed resources used by the invoker. (Inherited from HttpMessageInvoker.)
Protected methodDispose(Boolean)Releases the unmanaged resources used by the HttpClient and optionally disposes of the managed resources. (Overrides HttpMessageInvoker::Dispose(Boolean).)
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetAsync(String)Sends a GET request to the specified Uri as an asynchronous operation.
Public methodGetAsync(Uri)Sends a GET request to the specified Uri as an asynchronous operation.
Public methodGetAsync(String, HttpCompletionOption)Sends a GET request to the specified Uri with an HTTP completion option as an asynchronous operation.
Public methodGetAsync(String, CancellationToken)Sends a GET request to the specified Uri with a cancellation token as an asynchronous operation.
Public methodGetAsync(Uri, HttpCompletionOption)Sends a GET request to the specified Uri with an HTTP completion option as an asynchronous operation.
Public methodGetAsync(Uri, CancellationToken)Sends a GET request to the specified Uri with a cancellation token as an asynchronous operation.
Public methodGetAsync(String, HttpCompletionOption, CancellationToken)Sends a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation.
Public methodGetAsync(Uri, HttpCompletionOption, CancellationToken)Sends a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation.
Public methodGetByteArrayAsync(String)Sends a GET request to the specified Uri and returns the response body as a byte array in an asynchronous operation.
Public methodGetByteArrayAsync(Uri)Sends a GET request to the specified Uri and returns the response body as a byte array in an asynchronous operation.
Public methodGetHashCode (Inherited from Object.)
Public methodGetStreamAsync(String)Sends a GET request to the specified Uri and returns the response body as a stream in an asynchronous operation.
Public methodGetStreamAsync(Uri)Sends a GET request to the specified Uri and returns the response body as a stream in an asynchronous operation.
Public methodGetStringAsync(String)Sends a GET request to the specified Uri and returns the response body as a string in an asynchronous operation.
Public methodGetStringAsync(Uri)Sends a GET request to the specified Uri and returns the response body as a string in an asynchronous operation.
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodPostAsync(String, HttpContent)Sends a POST request to the specified Uri as an asynchronous operation.
Public methodPostAsync(Uri, HttpContent)Sends a POST request to the specified Uri as an asynchronous operation.
Public methodPostAsync(String, HttpContent, CancellationToken)Sends a POST request with a cancellation token as an asynchronous operation.
Public methodPostAsync(Uri, HttpContent, CancellationToken)Sends a POST request with a cancellation token as an asynchronous operation.
Public methodPutAsync(String, HttpContent)Sends a PUT request to the specified Uri as an asynchronous operation.
Public methodPutAsync(Uri, HttpContent)Sends a PUT request to the specified Uri as an asynchronous operation.
Public methodPutAsync(String, HttpContent, CancellationToken)Sends a PUT request with a cancellation token as an asynchronous operation.
Public methodPutAsync(Uri, HttpContent, CancellationToken)Sends a PUT request with a cancellation token as an asynchronous operation.
Public methodSendAsync(HttpRequestMessage)Sends an HTTP request as an asynchronous operation.
Public methodSendAsync(HttpRequestMessage, HttpCompletionOption)Sends an HTTP request with an HTTP completion option as an asynchronous operation.
Public methodSendAsync(HttpRequestMessage, CancellationToken)Sends an HTTP request with a cancellation token as an asynchronous operation. (Overrides HttpMessageInvoker::SendAsync(HttpRequestMessage, CancellationToken).)
Public methodSendAsync(HttpRequestMessage, HttpCompletionOption, CancellationToken)Sends an HTTP request with an HTTP completion option and cancellation token as an asynchronous operation.
Public methodToString (Inherited from Object.)
Top

For a complete example of using the HttpClient class, see Calling a Web API From a .NET Client

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft