Class HttpManager
Provides ways for sending HTTP requests and receiving HTTP responses from a resource identified by a URI.
public class HttpManager : Disposable, IDisposable
- Inheritance
-
HttpManager
- Implements
- Inherited Members
Constructors
HttpManager(Action<HttpManagerOptions>)
Initializes a new instance of the HttpManager class.
public HttpManager(Action<HttpManagerOptions> setup = null)
Parameters
setupAction<HttpManagerOptions>The HttpManagerOptions which may be configured.
Exceptions
- ArgumentNullException
The HandlerFactory of the
setupdelegate cannot be null.
HttpManager(Func<HttpClient>)
Initializes a new instance of the HttpManager class.
public HttpManager(Func<HttpClient> clientFactory)
Parameters
clientFactoryFunc<HttpClient>The function delegate that creates and configures an HttpClient instance.
Properties
DefaultRequestHeaders
Gets the headers which should be sent with each request.
public HttpRequestHeaders DefaultRequestHeaders { get; }
Property Value
- HttpRequestHeaders
The headers which should be sent with each request.
Timeout
Gets or sets the timespan to wait before the request times out.
public TimeSpan Timeout { get; set; }
Property Value
- TimeSpan
The timespan to wait before the request times out.
Methods
HttpAsync(HttpMethod, Uri, MediaTypeHeaderValue, Stream, CancellationToken)
Send a request as an asynchronous operation.
public Task<HttpResponseMessage> HttpAsync(HttpMethod method, Uri location, MediaTypeHeaderValue contentType, Stream content, CancellationToken ct = default)
Parameters
methodHttpMethodThe HTTP method.
locationUriThe Uri to request.
contentTypeMediaTypeHeaderValueThe Content-Type header of the HTTP request sent to the server.
contentStreamThe HTTP request content sent to the server.
ctCancellationTokenThe cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
Exceptions
- ArgumentNullException
methodcannot be null -or-locationcannot be null -or-contentTypecannot be null -or-contentcannot be null.
HttpAsync(HttpMethod, Uri, string, Stream, CancellationToken)
Send a request as an asynchronous operation.
public Task<HttpResponseMessage> HttpAsync(HttpMethod method, Uri location, string contentType, Stream content, CancellationToken ct = default)
Parameters
methodHttpMethodThe HTTP method.
locationUriThe Uri to request.
contentTypestringThe Content-Type header of the HTTP request sent to the server.
contentStreamThe HTTP request content sent to the server.
ctCancellationTokenThe cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
Exceptions
- ArgumentNullException
methodcannot be null -or-locationcannot be null -or-contentTypecannot be null -or-contentcannot be null.
HttpAsync(Uri, Action<HttpRequestOptions>)
Send a request as an asynchronous operation.
public virtual Task<HttpResponseMessage> HttpAsync(Uri location, Action<HttpRequestOptions> setup)
Parameters
locationUriThe Uri to request.
setupAction<HttpRequestOptions>The HttpRequestOptions which need to be configured.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
Exceptions
- ArgumentNullException
locationcannot be null -or-setupcannot be null.
HttpDeleteAsync(Uri, CancellationToken)
Send a DELETE request to the specified Uri as an asynchronous operation.
public Task<HttpResponseMessage> HttpDeleteAsync(Uri location, CancellationToken ct = default)
Parameters
locationUriThe Uri to request.
ctCancellationTokenThe cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
HttpGetAsync(Uri, CancellationToken)
Send a GET request to the specified Uri as an asynchronous operation.
public Task<HttpResponseMessage> HttpGetAsync(Uri location, CancellationToken ct = default)
Parameters
locationUriThe Uri to request.
ctCancellationTokenThe cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
HttpHeadAsync(Uri, CancellationToken)
Send a HEAD request to the specified Uri as an asynchronous operation.
public Task<HttpResponseMessage> HttpHeadAsync(Uri location, CancellationToken ct = default)
Parameters
locationUriThe Uri to request.
ctCancellationTokenThe cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
HttpOptionsAsync(Uri, CancellationToken)
Send an OPTIONS request to the specified Uri as an asynchronous operation.
public Task<HttpResponseMessage> HttpOptionsAsync(Uri location, CancellationToken ct = default)
Parameters
locationUriThe Uri to request.
ctCancellationTokenThe cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
HttpPatchAsync(Uri, MediaTypeHeaderValue, Stream, CancellationToken)
Send a PATCH request to the specified Uri as an asynchronous operation.
public Task<HttpResponseMessage> HttpPatchAsync(Uri location, MediaTypeHeaderValue contentType, Stream content, CancellationToken ct = default)
Parameters
locationUriThe Uri to request.
contentTypeMediaTypeHeaderValueThe Content-Type header of the HTTP request sent to the server.
contentStreamThe HTTP request content sent to the server.
ctCancellationTokenThe cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
Exceptions
- ArgumentNullException
contentTypecannot be null -or-contentcannot be null.
HttpPatchAsync(Uri, string, Stream, CancellationToken)
Send a PATCH request to the specified Uri as an asynchronous operation.
public Task<HttpResponseMessage> HttpPatchAsync(Uri location, string contentType, Stream content, CancellationToken ct = default)
Parameters
locationUriThe Uri to request.
contentTypestringThe Content-Type header of the HTTP request sent to the server.
contentStreamThe HTTP request content sent to the server.
ctCancellationTokenThe cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
Exceptions
- ArgumentNullException
contentTypecannot be null -or-contentcannot be null.
HttpPostAsync(Uri, MediaTypeHeaderValue, Stream, CancellationToken)
Send a POST request to the specified Uri as an asynchronous operation.
public Task<HttpResponseMessage> HttpPostAsync(Uri location, MediaTypeHeaderValue contentType, Stream content, CancellationToken ct = default)
Parameters
locationUriThe Uri to request.
contentTypeMediaTypeHeaderValueThe Content-Type header of the HTTP request sent to the server.
contentStreamThe HTTP request content sent to the server.
ctCancellationTokenThe cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
Exceptions
- ArgumentNullException
contentTypecannot be null -or-contentcannot be null.
HttpPostAsync(Uri, string, Stream, CancellationToken)
Send a POST request to the specified Uri as an asynchronous operation.
public Task<HttpResponseMessage> HttpPostAsync(Uri location, string contentType, Stream content, CancellationToken ct = default)
Parameters
locationUriThe Uri to request.
contentTypestringThe Content-Type header of the HTTP request sent to the server.
contentStreamThe HTTP request content sent to the server.
ctCancellationTokenThe cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
Exceptions
- ArgumentNullException
contentTypecannot be null -or-contentcannot be null.
HttpPutAsync(Uri, MediaTypeHeaderValue, Stream, CancellationToken)
Send a PUT request to the specified Uri as an asynchronous operation.
public Task<HttpResponseMessage> HttpPutAsync(Uri location, MediaTypeHeaderValue contentType, Stream content, CancellationToken ct = default)
Parameters
locationUriThe Uri to request.
contentTypeMediaTypeHeaderValueThe Content-Type header of the HTTP request sent to the server.
contentStreamThe HTTP request content sent to the server.
ctCancellationTokenThe cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
Exceptions
- ArgumentNullException
contentTypecannot be null -or-contentcannot be null.
HttpPutAsync(Uri, string, Stream, CancellationToken)
Send a PUT request to the specified Uri as an asynchronous operation.
public Task<HttpResponseMessage> HttpPutAsync(Uri location, string contentType, Stream content, CancellationToken ct = default)
Parameters
locationUriThe Uri to request.
contentTypestringThe Content-Type header of the HTTP request sent to the server.
contentStreamThe HTTP request content sent to the server.
ctCancellationTokenThe cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
Exceptions
- ArgumentNullException
contentTypecannot be null -or-contentcannot be null.
HttpTraceAsync(Uri, CancellationToken)
Send a TRACE request to the specified Uri as an asynchronous operation.
public Task<HttpResponseMessage> HttpTraceAsync(Uri location, CancellationToken ct = default)
Parameters
locationUriThe Uri to request.
ctCancellationTokenThe cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
OnDisposeManagedResources()
Called when this object is being disposed by either Dispose() or Dispose(bool) having disposing set to true and Disposed is false.
protected override void OnDisposeManagedResources()