Skip to main content
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 Class HttpClient _
	Inherits [%$TOPIC/hh193681_en-us_VS_118_2_0_0_0_0%]
Dim instance As HttpClient
public class HttpClient : [%$TOPIC/hh193681_en-us_VS_118_2_0_2_0_0%]
public ref class HttpClient : public [%$TOPIC/hh193681_en-us_VS_118_2_0_3_0_0%]
type HttpClient =  
    class 
        inherit [%$TOPIC/hh193681_en-us_VS_118_2_0_4_0_0%] 
    end
public class HttpClient extends [%$TOPIC/hh193681_en-us_VS_118_2_0_5_0_0%]

The HttpClient type exposes the following members.

  NameDescription
Public method HttpClientInitializes a new instance of the HttpClient class.
Public method HttpClient(HttpMessageHandler)Initializes a new instance of the HttpClient class with a specific handler.
Public method HttpClient(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 property BaseAddressGets or sets the base address of Uniform Resource Identifier (URI) of the Internet resource used when sending requests.
Public property DefaultRequestHeadersGets the headers which should be sent with each request.
Public property MaxResponseContentBufferSizeGets or sets the maximum number of bytes to buffer when reading the response content.
Public property TimeoutGets or sets the number of milliseconds to wait before the request times out.
Top
  NameDescription
Public method CancelPendingRequestsCancel all pending requests on this instance.
Public method DeleteAsync(String)Sends a DELETE request to the specified Uri as an asynchronous operation.
Public method DeleteAsync(Uri)Sends a DELETE request to the specified Uri as an asynchronous operation.
Public method DeleteAsync(String, CancellationToken)Sends a DELETE request to the specified Uri with a cancellation token as an asynchronous operation.
Public method DeleteAsync(Uri, CancellationToken)Sends a DELETE request to the specified Uri with a cancellation token as an asynchronous operation.
Public method DisposeReleases the unmanaged resources and disposes of the managed resources used by the invoker. (Inherited from HttpMessageInvoker.)
Protected method Dispose(Boolean)Releases the unmanaged resources used by the HttpClient and optionally disposes of the managed resources. (Overrides HttpMessageInvokerDispose(Boolean).)
Public method Equals (Inherited from Object.)
Protected method Finalize (Inherited from Object.)
Public method GetAsync(String)Sends a GET request to the specified Uri as an asynchronous operation.
Public method GetAsync(Uri)Sends a GET request to the specified Uri as an asynchronous operation.
Public method GetAsync(String, HttpCompletionOption)Sends a GET request to the specified Uri with an HTTP completion option as an asynchronous operation.
Public method GetAsync(String, CancellationToken)Sends a GET request to the specified Uri with a cancellation token as an asynchronous operation.
Public method GetAsync(Uri, HttpCompletionOption)Sends a GET request to the specified Uri with an HTTP completion option as an asynchronous operation.
Public method GetAsync(Uri, CancellationToken)Sends a GET request to the specified Uri with a cancellation token as an asynchronous operation.
Public method GetAsync(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 method GetAsync(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 method GetByteArrayAsync(String)Sends a GET request to the specified Uri and returns the response body as a byte array in an asynchronous operation.
Public method GetByteArrayAsync(Uri)Sends a GET request to the specified Uri and returns the response body as a byte array in an asynchronous operation.
Public method GetHashCode (Inherited from Object.)
Public method GetStreamAsync(String)Sends a GET request to the specified Uri and returns the response body as a stream in an asynchronous operation.
Public method GetStreamAsync(Uri)Sends a GET request to the specified Uri and returns the response body as a stream in an asynchronous operation.
Public method GetStringAsync(String)Sends a GET request to the specified Uri and returns the response body as a string in an asynchronous operation.
Public method GetStringAsync(Uri)Sends a GET request to the specified Uri and returns the response body as a string in an asynchronous operation.
Public method GetType (Inherited from Object.)
Protected method MemberwiseClone (Inherited from Object.)
Public method PostAsync(String, HttpContent)Sends a POST request to the specified Uri as an asynchronous operation.
Public method PostAsync(Uri, HttpContent)Sends a POST request to the specified Uri as an asynchronous operation.
Public method PostAsync(String, HttpContent, CancellationToken)Sends a POST request with a cancellation token as an asynchronous operation.
Public method PostAsync(Uri, HttpContent, CancellationToken)Sends a POST request with a cancellation token as an asynchronous operation.
Public method PutAsync(String, HttpContent)Sends a PUT request to the specified Uri as an asynchronous operation.
Public method PutAsync(Uri, HttpContent)Sends a PUT request to the specified Uri as an asynchronous operation.
Public method PutAsync(String, HttpContent, CancellationToken)Sends a PUT request with a cancellation token as an asynchronous operation.
Public method PutAsync(Uri, HttpContent, CancellationToken)Sends a PUT request with a cancellation token as an asynchronous operation.
Public method SendAsync(HttpRequestMessage)Sends an HTTP request as an asynchronous operation.
Public method SendAsync(HttpRequestMessage, HttpCompletionOption)Sends an HTTP request with an HTTP completion option as an asynchronous operation.
Public method SendAsync(HttpRequestMessage, CancellationToken)Sends an HTTP request with a cancellation token as an asynchronous operation. (Overrides HttpMessageInvokerSendAsync(HttpRequestMessage, CancellationToken).)
Public method SendAsync(HttpRequestMessage, HttpCompletionOption, CancellationToken)Sends an HTTP request with an HTTP completion option and cancellation token as an asynchronous operation.
Public method ToString (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.