Table of Contents

Class HttpManager

Namespace
Cuemon.Net.Http
Assembly
Cuemon.Net.dll

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

setup Action<HttpManagerOptions>

The HttpManagerOptions which may be configured.

Exceptions

ArgumentNullException

The HandlerFactory of the setup delegate cannot be null.

HttpManager(Func<HttpClient>)

Initializes a new instance of the HttpManager class.

public HttpManager(Func<HttpClient> clientFactory)

Parameters

clientFactory Func<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(CancellationToken))

Parameters

method HttpMethod

The HTTP method.

location Uri

The Uri to request.

contentType MediaTypeHeaderValue

The Content-Type header of the HTTP request sent to the server.

content Stream

The HTTP request content sent to the server.

ct CancellationToken

The cancellation token to cancel operation.

Returns

Task<HttpResponseMessage>

The task object representing the asynchronous operation.

Exceptions

ArgumentNullException

method cannot be null -or- location cannot be null -or- contentType cannot be null -or- content cannot 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(CancellationToken))

Parameters

method HttpMethod

The HTTP method.

location Uri

The Uri to request.

contentType String

The Content-Type header of the HTTP request sent to the server.

content Stream

The HTTP request content sent to the server.

ct CancellationToken

The cancellation token to cancel operation.

Returns

Task<HttpResponseMessage>

The task object representing the asynchronous operation.

Exceptions

ArgumentNullException

method cannot be null -or- location cannot be null -or- contentType cannot be null -or- content cannot be null.

HttpAsync(Uri, Action<HttpRequestOptions>)

Send a request as an asynchronous operation.

public virtual Task<HttpResponseMessage> HttpAsync(Uri location, Action<HttpRequestOptions> setup)

Parameters

location Uri

The Uri to request.

setup Action<HttpRequestOptions>

The HttpRequestOptions which need to be configured.

Returns

Task<HttpResponseMessage>

The task object representing the asynchronous operation.

Exceptions

ArgumentNullException

location cannot be null -or- setup cannot 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(CancellationToken))

Parameters

location Uri

The Uri to request.

ct CancellationToken

The 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(CancellationToken))

Parameters

location Uri

The Uri to request.

ct CancellationToken

The 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(CancellationToken))

Parameters

location Uri

The Uri to request.

ct CancellationToken

The 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(CancellationToken))

Parameters

location Uri

The Uri to request.

ct CancellationToken

The 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(CancellationToken))

Parameters

location Uri

The Uri to request.

contentType MediaTypeHeaderValue

The Content-Type header of the HTTP request sent to the server.

content Stream

The HTTP request content sent to the server.

ct CancellationToken

The cancellation token to cancel operation.

Returns

Task<HttpResponseMessage>

The task object representing the asynchronous operation.

Exceptions

ArgumentNullException

contentType cannot be null -or- content cannot 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(CancellationToken))

Parameters

location Uri

The Uri to request.

contentType String

The Content-Type header of the HTTP request sent to the server.

content Stream

The HTTP request content sent to the server.

ct CancellationToken

The cancellation token to cancel operation.

Returns

Task<HttpResponseMessage>

The task object representing the asynchronous operation.

Exceptions

ArgumentNullException

contentType cannot be null -or- content cannot 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(CancellationToken))

Parameters

location Uri

The Uri to request.

contentType MediaTypeHeaderValue

The Content-Type header of the HTTP request sent to the server.

content Stream

The HTTP request content sent to the server.

ct CancellationToken

The cancellation token to cancel operation.

Returns

Task<HttpResponseMessage>

The task object representing the asynchronous operation.

Exceptions

ArgumentNullException

contentType cannot be null -or- content cannot 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(CancellationToken))

Parameters

location Uri

The Uri to request.

contentType String

The Content-Type header of the HTTP request sent to the server.

content Stream

The HTTP request content sent to the server.

ct CancellationToken

The cancellation token to cancel operation.

Returns

Task<HttpResponseMessage>

The task object representing the asynchronous operation.

Exceptions

ArgumentNullException

contentType cannot be null -or- content cannot 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(CancellationToken))

Parameters

location Uri

The Uri to request.

contentType MediaTypeHeaderValue

The Content-Type header of the HTTP request sent to the server.

content Stream

The HTTP request content sent to the server.

ct CancellationToken

The cancellation token to cancel operation.

Returns

Task<HttpResponseMessage>

The task object representing the asynchronous operation.

Exceptions

ArgumentNullException

contentType cannot be null -or- content cannot 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(CancellationToken))

Parameters

location Uri

The Uri to request.

contentType String

The Content-Type header of the HTTP request sent to the server.

content Stream

The HTTP request content sent to the server.

ct CancellationToken

The cancellation token to cancel operation.

Returns

Task<HttpResponseMessage>

The task object representing the asynchronous operation.

Exceptions

ArgumentNullException

contentType cannot be null -or- content cannot 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(CancellationToken))

Parameters

location Uri

The Uri to request.

ct CancellationToken

The 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(Boolean) having disposing set to true and Disposed is false.

protected override void OnDisposeManagedResources()

See Also