Class ServiceHttpClient
An implementation of an HTTP client which abstracts the Task of sending HttpRequestMessage.
Inherited Members
Namespace: Unity.Cloud.Common
Syntax
public class ServiceHttpClient : IServiceHttpClient, IHttpClient
Constructors
ServiceHttpClient(IHttpClient, IAccessTokenProvider, IAppIdProvider)
Initializes and returns an instance of ServiceHttpClient
Declaration
public ServiceHttpClient(IHttpClient baseHttpClient, IAccessTokenProvider accessTokenProvider, IAppIdProvider appIdProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| IHttpClient | baseHttpClient | The base HTTP client. |
| IAccessTokenProvider | accessTokenProvider | The access token provider to authenticate requests. |
| IAppIdProvider | appIdProvider | The App ID provider. |
Properties
Timeout
The timespan to wait before the request times out.
Declaration
public TimeSpan Timeout { get; set; }
Property Value
| Type | Description |
|---|---|
| TimeSpan |
Implements
Methods
DownloadFileAsync(HttpRequestMessage, String, CancellationToken)
Send an asynchronous file download request.
Declaration
public Task<HttpResponseMessage> DownloadFileAsync(HttpRequestMessage request, string downloadFilePath, CancellationToken cancellationToken = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| HttpRequestMessage | request | The request to be sent. |
| String | downloadFilePath | Optional path to save downloaded files. |
| CancellationToken | cancellationToken | Optional cancellation token that will try to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> | A task that will hold the HttpResponseMessage once the request is completed |
Implements
SendAsync(HttpRequestMessage, CancellationToken)
Send an asynchronous HTTP request.
Declaration
public Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| HttpRequestMessage | request | The request to be sent. |
| CancellationToken | cancellationToken | Optional cancellation token that will try to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> | A task that will hold the HttpResponseMessage once the request is completed |
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when the request 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(HttpRequestMessage, ServiceHttpClientOptions, CancellationToken)
Send an asynchronous HTTP request.
Declaration
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, ServiceHttpClientOptions options, CancellationToken cancellationToken = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| HttpRequestMessage | request | The request to be sent. |
| ServiceHttpClientOptions | options | The options for the client. |
| CancellationToken | cancellationToken | Optional cancellation token that will try to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> | A task that will hold the HttpResponseMessage once the request is completed |
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when the request 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. |