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
- IDisposable Implemented by: HttpMessageInvoker
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.
public
HttpRequestHeaders
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.
public
HttpVersionPolicy
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​IO.​Stream>
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.
public
Threading.​Tasks.​Task<​IO.​Stream>
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.
public
Threading.​Tasks.​Task<​IO.​Stream>
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.
public
Threading.​Tasks.​Task<​IO.​Stream>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
HttpResponseMessage
Send​(HttpRequestMessage request)
Sends an HTTP request with the specified request.
Returns An HTTP response message.
request
The HTTP request message to send.
public
HttpResponseMessage
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).
public
HttpResponseMessage
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.
public
HttpResponseMessage
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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).
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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.
public
Threading.​Tasks.​Task<​HttpResponseMessage>
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
protected
object
MemberwiseClone​()
Inherited from object
public
string
ToString​()
Inherited from object