Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Net.​Http.​HttpClient

Assembly: System.Net.Http

Inheritance: object → HttpMessageInvoker → HttpClient

Implemented Interfaces

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

Properties

public Uri
BaseAddress
Gets or sets the base address of Uniform Resource Identifier (URI) of the Internet resource used when sending requests.
public static IWebProxy
DefaultProxy
Gets or sets the global HTTP proxy.
DefaultRequestHeaders
Gets the headers which should be sent with each request.
public Version
DefaultRequestVersion
Gets or sets the default HTTP version used on subsequent requests made by this <see cref="T:System.Net.Http.HttpClient" /> instance.
DefaultVersionPolicy
Gets or sets the default version policy for implicitly created requests in convenience methods, for example, <see cref="M:System.Net.Http.HttpClient.GetAsync(System.String)" /> and <see cref="M:System.Net.Http.HttpClient.PostAsync(System.String,System.Net.Http.HttpContent)" /> .
public long
MaxResponseContentBufferSize
Gets or sets the maximum number of bytes to buffer when reading the response content.
public TimeSpan
Timeout
Gets or sets the timespan to wait before the request times out.

Methods

public void
CancelPendingRequests​()
Cancel all pending requests on this instance.
DeleteAsync​(string requestUri)
Send a DELETE request to the specified URI as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
DeleteAsync​(string requestUri, Threading.​CancellationToken cancellationToken)
Send a DELETE request to the specified URI with a cancellation token as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
cancellationToken A cancellation token that can be used by other objects or threads to receive notice of cancellation.
DeleteAsync​(Uri? requestUri)
Send a DELETE request to the specified URI as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
DeleteAsync​(Uri? requestUri, Threading.​CancellationToken cancellationToken)
Send a DELETE request to the specified URI with a cancellation token as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
cancellationToken A cancellation token that can be used by other objects or threads to receive notice of cancellation.
protected void
Dispose​(bool disposing)
Releases the unmanaged resources used by the <see cref="T:System.Net.Http.HttpClient" /> and optionally disposes of the managed resources.
disposing <see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to releases only unmanaged resources.
GetAsync​(string requestUri)
Send a GET request to the specified URI as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
GetAsync​(string requestUri, HttpCompletionOption completionOption)
Send a GET request to the specified URI with an HTTP completion option as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
completionOption An HTTP completion option value that indicates when the operation should be considered completed.
GetAsync​(string requestUri, HttpCompletionOption completionOption, Threading.​CancellationToken cancellationToken)
Send a GET request to the specified URI with an HTTP completion option and a cancellation token as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
completionOption An HTTP completion option value that indicates when the operation should be considered completed.
cancellationToken A cancellation token that can be used by other objects or threads to receive notice of cancellation.
GetAsync​(string requestUri, Threading.​CancellationToken cancellationToken)
Send a GET request to the specified URI with a cancellation token as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
cancellationToken A cancellation token that can be used by other objects or threads to receive notice of cancellation.
GetAsync​(Uri? requestUri)
Send a GET request to the specified URI as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
GetAsync​(Uri? requestUri, HttpCompletionOption completionOption)
Send a GET request to the specified URI with an HTTP completion option as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
completionOption An HTTP completion option value that indicates when the operation should be considered completed.
GetAsync​(Uri? requestUri, HttpCompletionOption completionOption, Threading.​CancellationToken cancellationToken)
Send a GET request to the specified URI with an HTTP completion option and a cancellation token as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
completionOption An HTTP completion option value that indicates when the operation should be considered completed.
cancellationToken A cancellation token that can be used by other objects or threads to receive notice of cancellation.
GetAsync​(Uri? requestUri, Threading.​CancellationToken cancellationToken)
Send a GET request to the specified URI with a cancellation token as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
cancellationToken A cancellation token that can be used by other objects or threads to receive notice of cancellation.
public Threading.​Tasks.​Task<​byte[]>
GetByteArrayAsync​(string requestUri)
Sends a GET request to the specified URI and return the response body as a byte array in an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
public Threading.​Tasks.​Task<​byte[]>
GetByteArrayAsync​(string requestUri, Threading.​CancellationToken cancellationToken)
Sends a GET request to the specified URI and return the response body as a byte array in an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
cancellationToken The cancellation token to cancel the operation.
public Threading.​Tasks.​Task<​byte[]>
GetByteArrayAsync​(Uri? requestUri)
Send a GET request to the specified URI and return the response body as a byte array in an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
public Threading.​Tasks.​Task<​byte[]>
GetByteArrayAsync​(Uri? requestUri, Threading.​CancellationToken cancellationToken)
Send a GET request to the specified URI and return the response body as a byte array in an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
cancellationToken The cancellation token to cancel the operation.
GetStreamAsync​(string requestUri)
Send a GET request to the specified URI and return the response body as a stream in an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
GetStreamAsync​(string requestUri, Threading.​CancellationToken cancellationToken)
Send a GET request to the specified URI and return the response body as a stream in an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
cancellationToken The cancellation token to cancel the operation.
GetStreamAsync​(Uri? requestUri)
Send a GET request to the specified URI and return the response body as a stream in an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
GetStreamAsync​(Uri? requestUri, Threading.​CancellationToken cancellationToken)
Send a GET request to the specified URI and return the response body as a stream in an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
cancellationToken The cancellation token to cancel the operation.
public Threading.​Tasks.​Task<​string>
GetStringAsync​(string requestUri)
Send a GET request to the specified URI and return the response body as a string in an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
public Threading.​Tasks.​Task<​string>
GetStringAsync​(string requestUri, Threading.​CancellationToken cancellationToken)
Send a GET request to the specified URI and return the response body as a string in an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
cancellationToken The cancellation token to cancel the operation.
public Threading.​Tasks.​Task<​string>
GetStringAsync​(Uri? requestUri)
Send a GET request to the specified URI and return the response body as a string in an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
public Threading.​Tasks.​Task<​string>
GetStringAsync​(Uri? requestUri, Threading.​CancellationToken cancellationToken)
Send a GET request to the specified URI and return the response body as a string in an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
cancellationToken The cancellation token to cancel the operation.
PatchAsync​(string requestUri, HttpContent content)
Sends a PATCH request to a URI designated as a string as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
content The HTTP request content sent to the server.
PatchAsync​(string requestUri, HttpContent content, Threading.​CancellationToken cancellationToken)
Sends a PATCH request with a cancellation token to a URI represented as a string as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
content The HTTP request content sent to the server.
cancellationToken A cancellation token that can be used by other objects or threads to receive notice of cancellation.
PatchAsync​(Uri requestUri, HttpContent content)
Sends a PATCH request as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
content The HTTP request content sent to the server.
PatchAsync​(Uri requestUri, HttpContent content, Threading.​CancellationToken cancellationToken)
Sends a PATCH request with a cancellation token as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
content The HTTP request content sent to the server.
cancellationToken A cancellation token that can be used by other objects or threads to receive notice of cancellation.
PostAsync​(string requestUri, HttpContent content)
Send a POST request to the specified URI as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
content The HTTP request content sent to the server.
PostAsync​(string requestUri, HttpContent content, Threading.​CancellationToken cancellationToken)
Send a POST request with a cancellation token as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
content The HTTP request content sent to the server.
cancellationToken A cancellation token that can be used by other objects or threads to receive notice of cancellation.
PostAsync​(Uri requestUri, HttpContent content)
Send a POST request to the specified URI as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
content The HTTP request content sent to the server.
PostAsync​(Uri requestUri, HttpContent content, Threading.​CancellationToken cancellationToken)
Send a POST request with a cancellation token as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
content The HTTP request content sent to the server.
cancellationToken A cancellation token that can be used by other objects or threads to receive notice of cancellation.
PutAsync​(string requestUri, HttpContent content)
Send a PUT request to the specified URI as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
content The HTTP request content sent to the server.
PutAsync​(string requestUri, HttpContent content, Threading.​CancellationToken cancellationToken)
Send a PUT request with a cancellation token as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
content The HTTP request content sent to the server.
cancellationToken A cancellation token that can be used by other objects or threads to receive notice of cancellation.
PutAsync​(Uri requestUri, HttpContent content)
Send a PUT request to the specified URI as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
content The HTTP request content sent to the server.
PutAsync​(Uri requestUri, HttpContent content, Threading.​CancellationToken cancellationToken)
Send a PUT request with a cancellation token as an asynchronous operation.
Returns The task object representing the asynchronous operation.
requestUri The URI the request is sent to.
content The HTTP request content sent to the server.
cancellationToken A cancellation token that can be used by other objects or threads to receive notice of cancellation.
Send​(HttpRequestMessage request)
Sends an HTTP request with the specified request.
Returns An HTTP response message.
request The HTTP request message to send.
Send​(HttpRequestMessage request, HttpCompletionOption completionOption)
Sends an HTTP request.
Returns The HTTP response message.
request The HTTP request message to send.
completionOption One of the enumeration values that specifies when the operation should complete (as soon as a response is available or after reading the response content).
Send​(HttpRequestMessage request, HttpCompletionOption completionOption, Threading.​CancellationToken cancellationToken)
Sends an HTTP request with the specified request, completion option and cancellation token.
Returns The HTTP response message.
request The HTTP request message to send.
completionOption One of the enumeration values that specifies when the operation should complete (as soon as a response is available or after reading the response content).
cancellationToken The token to cancel the operation.
Send​(HttpRequestMessage request, Threading.​CancellationToken cancellationToken)
Sends an HTTP request with the specified request and cancellation token.
Returns The HTTP response message.
request The HTTP request message to send.
cancellationToken The token to cancel the operation.
SendAsync​(HttpRequestMessage request)
Send an HTTP request as an asynchronous operation.
Returns The task object representing the asynchronous operation.
request The HTTP request message to send.
SendAsync​(HttpRequestMessage request, HttpCompletionOption completionOption)
Send an HTTP request as an asynchronous operation.
Returns The task object representing the asynchronous operation.
request The HTTP request message to send.
completionOption When the operation should complete (as soon as a response is available or after reading the whole response content).
SendAsync​(HttpRequestMessage request, HttpCompletionOption completionOption, Threading.​CancellationToken cancellationToken)
Send an HTTP request as an asynchronous operation.
Returns The task object representing the asynchronous operation.
request The HTTP request message to send.
completionOption When the operation should complete (as soon as a response is available or after reading the whole response content).
cancellationToken The cancellation token to cancel operation.
SendAsync​(HttpRequestMessage request, Threading.​CancellationToken cancellationToken)
Send an HTTP request as an asynchronous operation.
Returns The task object representing the asynchronous operation.
request The HTTP request message to send.
cancellationToken The cancellation token to cancel operation.
public void
Dispose​()
Inherited from HttpMessageInvoker
Releases the unmanaged resources and disposes of the managed resources used by the <see cref="T:System.Net.Http.HttpMessageInvoker" /> .
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object