Class HttpClientExtensions
Helper methods for IHttpClient.
Inherited Members
Namespace: Unity.Cloud.Common
Assembly: Unity.Cloud.Common.dll
Syntax
public static class HttpClientExtensions
Properties
HttpMethodPatch
An HttpMethod for "PATCH".
Declaration
public static HttpMethod HttpMethodPatch { get; }
Property Value
Type | Description |
---|---|
HttpMethod |
Methods
CreateHttpRequestMessage(HttpMethod, Uri)
Creates an HttpRequestMessage from an HttpMethod and a Uri.
Declaration
public static HttpRequestMessage CreateHttpRequestMessage(HttpMethod httpMethod, Uri uri)
Parameters
Type | Name | Description |
---|---|---|
HttpMethod | httpMethod | The HTTP method. |
Uri | uri | The Uri to request. |
Returns
Type | Description |
---|---|
HttpRequestMessage | The created HttpRequestMessage. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the URI is null. |
CreateUri(string)
Declaration
public static Uri CreateUri(string uri)
Parameters
Type | Name | Description |
---|---|---|
string | uri | The string to convert. |
Returns
Type | Description |
---|---|
Uri | The created Uri. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when an unhandled exception is thrown constructing the URI. |
DeleteAsync(IHttpClient, string, HttpCompletionOption, IProgress<HttpProgress>, CancellationToken)
Sends an asynchronous DELETE request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> DeleteAsync(this IHttpClient httpClient, string requestUri, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, IProgress<HttpProgress> progress = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IHttpClient | httpClient | The HTTP client. |
string | requestUri | The uri for the request. |
HttpCompletionOption | completionOption | When the operation should complete. |
IProgress<HttpProgress> | progress | The progress provider. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when the requestUri is invalid. |
HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
TimeoutException | Thrown when the request failed due to timeout. |
DeleteAsync(IHttpClient, string, HttpContent, HttpCompletionOption, IProgress<HttpProgress>, CancellationToken)
Sends an asynchronous DELETE request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> DeleteAsync(this IHttpClient httpClient, string requestUri, HttpContent content, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, IProgress<HttpProgress> progress = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IHttpClient | httpClient | The HTTP client. |
string | requestUri | The uri for the request. |
HttpContent | content | The HTTP content for the request. |
HttpCompletionOption | completionOption | When the operation should complete. |
IProgress<HttpProgress> | progress | The progress provider. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when the requestUri is invalid. |
HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
TimeoutException | Thrown when the request failed due to timeout. |
DeleteAsync(IHttpClient, Uri, HttpCompletionOption, IProgress<HttpProgress>, CancellationToken)
Sends an asynchronous DELETE request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> DeleteAsync(this IHttpClient httpClient, Uri requestUri, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, IProgress<HttpProgress> progress = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IHttpClient | httpClient | The HTTP client. |
Uri | requestUri | The uri for the request. |
HttpCompletionOption | completionOption | When the operation should complete. |
IProgress<HttpProgress> | progress | The progress provider. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the requestUri is null. |
HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
TimeoutException | Thrown when the request failed due to timeout. |
DeleteAsync(IHttpClient, Uri, HttpContent, HttpCompletionOption, IProgress<HttpProgress>, CancellationToken)
Sends an asynchronous DELETE request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> DeleteAsync(this IHttpClient httpClient, Uri requestUri, HttpContent content, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, IProgress<HttpProgress> progress = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IHttpClient | httpClient | The HTTP client. |
Uri | requestUri | The uri for the request. |
HttpContent | content | The HTTP content for the request. |
HttpCompletionOption | completionOption | When the operation should complete. |
IProgress<HttpProgress> | progress | The progress provider. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the requestUri is null. |
HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
TimeoutException | Thrown when the request failed due to timeout. |
GetAsync(IHttpClient, string, HttpCompletionOption, IProgress<HttpProgress>, CancellationToken)
Sends an asynchronous GET request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> GetAsync(this IHttpClient httpClient, string requestUri, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, IProgress<HttpProgress> progress = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IHttpClient | httpClient | The HTTP client. |
string | requestUri | The uri for the request. |
HttpCompletionOption | completionOption | When the operation should complete. |
IProgress<HttpProgress> | progress | The progress provider. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when the requestUri is invalid. |
HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
TimeoutException | Thrown when the request failed due to timeout. |
GetAsync(IHttpClient, Uri, HttpCompletionOption, IProgress<HttpProgress>, CancellationToken)
Sends an asynchronous GET request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> GetAsync(this IHttpClient httpClient, Uri requestUri, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, IProgress<HttpProgress> progress = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IHttpClient | httpClient | The HTTP client. |
Uri | requestUri | The uri for the request. |
HttpCompletionOption | completionOption | When the operation should complete. |
IProgress<HttpProgress> | progress | The progress provider. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the requestUri is null. |
HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
TimeoutException | Thrown when the request failed due to timeout. |
PatchAsync(IHttpClient, string, HttpContent, HttpCompletionOption, IProgress<HttpProgress>, CancellationToken)
Sends an asynchronous PATCH request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> PatchAsync(this IHttpClient httpClient, string requestUri, HttpContent content, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, IProgress<HttpProgress> progress = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IHttpClient | httpClient | The HTTP client. |
string | requestUri | The uri for the request. |
HttpContent | content | The HTTP content for the request. |
HttpCompletionOption | completionOption | When the operation should complete. |
IProgress<HttpProgress> | progress | The progress provider. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when the requestUri is invalid. |
HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
TimeoutException | Thrown when the request failed due to timeout. |
PatchAsync(IHttpClient, Uri, HttpContent, HttpCompletionOption, IProgress<HttpProgress>, CancellationToken)
Sends an asynchronous PATCH request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> PatchAsync(this IHttpClient httpClient, Uri requestUri, HttpContent content, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, IProgress<HttpProgress> progress = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IHttpClient | httpClient | The HTTP client. |
Uri | requestUri | The uri for the request. |
HttpContent | content | The HTTP content for the request. |
HttpCompletionOption | completionOption | When the operation should complete. |
IProgress<HttpProgress> | progress | The progress provider. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the requestUri is null. |
HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
TimeoutException | Thrown when the request failed due to timeout. |
PostAsync(IHttpClient, string, HttpContent, HttpCompletionOption, IProgress<HttpProgress>, CancellationToken)
Sends an asynchronous POST request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> PostAsync(this IHttpClient httpClient, string requestUri, HttpContent content, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, IProgress<HttpProgress> progress = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IHttpClient | httpClient | The HTTP client. |
string | requestUri | The uri for the request. |
HttpContent | content | The HTTP content for the request. |
HttpCompletionOption | completionOption | When the operation should complete. |
IProgress<HttpProgress> | progress | The progress provider. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when the requestUri is invalid. |
HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
TimeoutException | Thrown when the request failed due to timeout. |
PostAsync(IHttpClient, Uri, HttpContent, HttpCompletionOption, IProgress<HttpProgress>, CancellationToken)
Sends an asynchronous POST request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> PostAsync(this IHttpClient httpClient, Uri requestUri, HttpContent content, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, IProgress<HttpProgress> progress = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IHttpClient | httpClient | The HTTP client. |
Uri | requestUri | The uri for the request. |
HttpContent | content | The HTTP content for the request. |
HttpCompletionOption | completionOption | When the operation should complete. |
IProgress<HttpProgress> | progress | The progress provider. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the requestUri is null. |
HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
TimeoutException | Thrown when the request failed due to timeout. |
PutAsync(IHttpClient, string, HttpContent, HttpCompletionOption, IProgress<HttpProgress>, CancellationToken)
Sends an asynchronous PUT request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> PutAsync(this IHttpClient httpClient, string requestUri, HttpContent content, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, IProgress<HttpProgress> progress = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IHttpClient | httpClient | The HTTP client. |
string | requestUri | The uri for the request. |
HttpContent | content | The HTTP content for the request. |
HttpCompletionOption | completionOption | When the operation should complete. |
IProgress<HttpProgress> | progress | The progress provider. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when the requestUri is invalid. |
HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
TimeoutException | Thrown when the request failed due to timeout. |
PutAsync(IHttpClient, Uri, HttpContent, HttpCompletionOption, IProgress<HttpProgress>, CancellationToken)
Sends an asynchronous PUT request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> PutAsync(this IHttpClient httpClient, Uri requestUri, HttpContent content, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, IProgress<HttpProgress> progress = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IHttpClient | httpClient | The HTTP client. |
Uri | requestUri | The uri for the request. |
HttpContent | content | The HTTP content for the request. |
HttpCompletionOption | completionOption | When the operation should complete. |
IProgress<HttpProgress> | progress | The progress provider. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the requestUri is null. |
HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
TimeoutException | Thrown when the request failed due to timeout. |
SendAsync(IHttpClient, HttpRequestMessage)
Sends an asynchronous HTTP request.
Declaration
public static Task<HttpResponseMessage> SendAsync(this IHttpClient httpClient, HttpRequestMessage request)
Parameters
Type | Name | Description |
---|---|---|
IHttpClient | httpClient | The HTTP client. |
HttpRequestMessage | request | The request to be sent. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when the requestUri is invalid. |
HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
TimeoutException | Thrown when the request failed due to timeout. |
SendAsync(IHttpClient, HttpRequestMessage, HttpCompletionOption)
Sends an asynchronous HTTP request.
Declaration
public static Task<HttpResponseMessage> SendAsync(this IHttpClient httpClient, HttpRequestMessage request, HttpCompletionOption completionOption)
Parameters
Type | Name | Description |
---|---|---|
IHttpClient | httpClient | The HTTP client. |
HttpRequestMessage | request | The request to be sent. |
HttpCompletionOption | completionOption | When the operation should complete. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when the requestUri is invalid. |
HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
TimeoutException | Thrown when the request failed due to timeout. |
SendAsync(IHttpClient, HttpRequestMessage, HttpCompletionOption, CancellationToken)
Sends an asynchronous HTTP request.
Declaration
public static Task<HttpResponseMessage> SendAsync(this IHttpClient httpClient, HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
IHttpClient | httpClient | The HTTP client. |
HttpRequestMessage | request | The request to be sent. |
HttpCompletionOption | completionOption | When the operation should complete. |
CancellationToken | cancellationToken | Cancellation token that will try to cancel the operation. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when the requestUri is invalid. |
HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
TimeoutException | Thrown when the request failed due to timeout. |
SendAsync(IHttpClient, HttpRequestMessage, CancellationToken)
Sends an asynchronous HTTP request.
Declaration
public static Task<HttpResponseMessage> SendAsync(this IHttpClient httpClient, HttpRequestMessage request, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
IHttpClient | httpClient | The HTTP client. |
HttpRequestMessage | request | The request to be sent. |
CancellationToken | cancellationToken | Cancellation token that will try to cancel the operation. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when the requestUri is invalid. |
HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
TimeoutException | Thrown when the request failed due to timeout. |