Class HttpClientExtensions
HttpClient extension methods, mostly related to easily supporting custom headers.
Namespace: Neon.Common
Assembly: Neon.Common.dll
Syntax
public static class HttpClientExtensions
Methods
DeleteAsync(HttpClient, string, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a DELETE request to a string URI.
Declaration
public static Task<HttpResponseMessage> DeleteAsync(this HttpClient client, string requestUri, HttpContent content = null, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
DeleteAsync(HttpClient, Uri, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a DELETE request to a Uri.
Declaration
public static Task<HttpResponseMessage> DeleteAsync(this HttpClient client, Uri requestUri, HttpContent content = null, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
DeleteSafeAsync(HttpClient, string, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a DELETE request to a string URI ensuring that the operation succeeded.
Declaration
public static Task<HttpResponseMessage> DeleteSafeAsync(this HttpClient client, string requestUri, HttpContent content = null, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
DeleteSafeAsync(HttpClient, Uri, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a DELETE request to a Uri ensuring that the operation succeeded.
Declaration
public static Task<HttpResponseMessage> DeleteSafeAsync(this HttpClient client, Uri requestUri, HttpContent content = null, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
GetAsync(HttpClient, string, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a GET request to a specified Uri.
Declaration
public static Task<HttpResponseMessage> GetAsync(this HttpClient client, string requestUri, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
GetAsync(HttpClient, Uri, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a GET request to the specified string URI.
Declaration
public static Task<HttpResponseMessage> GetAsync(this HttpClient client, Uri requestUri, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
GetByteArrayAsync(HttpClient, string, ArgDictionary)
Sends a GET to a specified string URI and returns the response body as a byte array.
Declaration
public static Task<byte[]> GetByteArrayAsync(this HttpClient client, string requestUri, ArgDictionary headers = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
ArgDictionary | headers | Optional request headers. |
Returns
Type | Description |
---|---|
Task<byte[]> | The response byte array. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
GetByteArrayAsync(HttpClient, Uri, ArgDictionary)
Sends a GET to a specified Uri and returns the response body as a byte array.
Declaration
public static Task<byte[]> GetByteArrayAsync(this HttpClient client, Uri requestUri, ArgDictionary headers = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
ArgDictionary | headers | Optional request headers. |
Returns
Type | Description |
---|---|
Task<byte[]> | The response byte array. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
GetByteArraySafeAsync(HttpClient, string, ArgDictionary)
Sends a GET to a specified string URI and returns the response body as a byte array ensuring that the operation succeeded.
Declaration
public static Task<byte[]> GetByteArraySafeAsync(this HttpClient client, string requestUri, ArgDictionary headers = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
ArgDictionary | headers | Optional request headers. |
Returns
Type | Description |
---|---|
Task<byte[]> | The response byte array. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
GetByteArraySafeAsync(HttpClient, Uri, ArgDictionary)
Sends a GET to a specified Uri and returns the response body as a byte array ensuring that the operation succeeded.
Declaration
public static Task<byte[]> GetByteArraySafeAsync(this HttpClient client, Uri requestUri, ArgDictionary headers = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
ArgDictionary | headers | Optional request headers. |
Returns
Type | Description |
---|---|
Task<byte[]> | The response byte array. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
GetSafeAsync(HttpClient, string, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a GET request to a specified Uri ensuring that the operation succeeded.
Declaration
public static Task<HttpResponseMessage> GetSafeAsync(this HttpClient client, string requestUri, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
GetSafeAsync(HttpClient, Uri, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a GET request to the specified string URI ensuring that the operation succeeded.
Declaration
public static Task<HttpResponseMessage> GetSafeAsync(this HttpClient client, Uri requestUri, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
GetStreamAsync(HttpClient, string, ArgDictionary)
Sends a GET to a specified string URI and returns the response body as a Stream.
Declaration
public static Task<Stream> GetStreamAsync(this HttpClient client, string requestUri, ArgDictionary headers = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
ArgDictionary | headers | Optional request headers. |
Returns
Type | Description |
---|---|
Task<Stream> | The response stream. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
GetStreamAsync(HttpClient, Uri, ArgDictionary)
Declaration
public static Task<Stream> GetStreamAsync(this HttpClient client, Uri requestUri, ArgDictionary headers = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
ArgDictionary | headers | Optional request headers. |
Returns
Type | Description |
---|---|
Task<Stream> | The response stream. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
GetStreamSafeAsync(HttpClient, string, ArgDictionary)
Sends a GET to a specified string URI and returns the response body as a Stream ensuring that the operation succeeded.
Declaration
public static Task<Stream> GetStreamSafeAsync(this HttpClient client, string requestUri, ArgDictionary headers = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
ArgDictionary | headers | Optional request headers. |
Returns
Type | Description |
---|---|
Task<Stream> | The response stream. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
GetStreamSafeAsync(HttpClient, Uri, ArgDictionary)
Sends a GET to a specified Uri and returns the response body as a Stream ensuring that the operation succeeded.
Declaration
public static Task<Stream> GetStreamSafeAsync(this HttpClient client, Uri requestUri, ArgDictionary headers = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
ArgDictionary | headers | Optional request headers. |
Returns
Type | Description |
---|---|
Task<Stream> | The response stream. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
GetStringAsync(HttpClient, string, ArgDictionary)
Sends a GET request to a string URI and returns the response as a string.
Declaration
public static Task<string> GetStringAsync(this HttpClient client, string requestUri, ArgDictionary headers = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
ArgDictionary | headers | Optional request headers. |
Returns
Type | Description |
---|---|
Task<string> | The response string. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
GetStringAsync(HttpClient, Uri, ArgDictionary)
Sends a GET request to a Uri and returns the response as a string.
Declaration
public static Task<string> GetStringAsync(this HttpClient client, Uri requestUri, ArgDictionary headers = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
ArgDictionary | headers | Optional request headers. |
Returns
Type | Description |
---|---|
Task<string> | The response string. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
GetStringSafeAsync(HttpClient, string, ArgDictionary)
Sends a GET request to a string URI and returns the response as a string ensuring that the operation succeeded.
Declaration
public static Task<string> GetStringSafeAsync(this HttpClient client, string requestUri, ArgDictionary headers = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
ArgDictionary | headers | Optional request headers. |
Returns
Type | Description |
---|---|
Task<string> | The response string. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
GetStringSafeAsync(HttpClient, Uri, ArgDictionary)
Sends a GET request to a Uri and returns the response as a string ensuring that the operation succeeded.
Declaration
public static Task<string> GetStringSafeAsync(this HttpClient client, Uri requestUri, ArgDictionary headers = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
ArgDictionary | headers | Optional request headers. |
Returns
Type | Description |
---|---|
Task<string> | The response string. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
GetToFileSafeAsync(HttpClient, string, string, ArgDictionary)
Downloads the contents of a string URI to a file.
Declaration
public static Task<HttpResponseMessage> GetToFileSafeAsync(this HttpClient client, string requestUri, string outputPath, ArgDictionary headers = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
string | outputPath | The path to the output file. |
ArgDictionary | headers | Optional request headers. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The HttpResponseMessage making things like response headers available. |
GetToFileSafeAsync(HttpClient, Uri, string, ArgDictionary)
Downloads the contents of a string URI to a file.
Declaration
public static Task<HttpResponseMessage> GetToFileSafeAsync(this HttpClient client, Uri requestUri, string outputPath, ArgDictionary headers = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
string | outputPath | The path to the output file. |
ArgDictionary | headers | Optional request headers. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The HttpResponseMessage making things like response headers available. |
GetToStreamSafeAsync(HttpClient, string, Stream, ArgDictionary)
Downloads the contents of a string URI to a stream.
Declaration
public static Task<HttpResponseMessage> GetToStreamSafeAsync(this HttpClient client, string requestUri, Stream output, ArgDictionary headers = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
Stream | output | The stream where the URI contents will be written. |
ArgDictionary | headers | Optional request headers. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The HttpResponseMessage making things like response headers available. |
GetToStreamSafeAsync(HttpClient, Uri, Stream, ArgDictionary)
Downloads the contents of a URI to a stream.
Declaration
public static Task<HttpResponseMessage> GetToStreamSafeAsync(this HttpClient client, Uri requestUri, Stream output, ArgDictionary headers = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
Stream | output | The stream where the URI contents will be written. |
ArgDictionary | headers | Optional request headers. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The HttpResponseMessage making things like response headers available. |
HeadAsync(HttpClient, string, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a HEAD request to a string URI.
Declaration
public static Task<HttpResponseMessage> HeadAsync(this HttpClient client, string requestUri, HttpContent content = null, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
HeadAsync(HttpClient, Uri, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a HEAD request to a Uri.
Declaration
public static Task<HttpResponseMessage> HeadAsync(this HttpClient client, Uri requestUri, HttpContent content = null, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
HeadSafeAsync(HttpClient, string, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a HEAD request to a string URI ensuring that the operation succeeded.
Declaration
public static Task<HttpResponseMessage> HeadSafeAsync(this HttpClient client, string requestUri, HttpContent content = null, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
HeadSafeAsync(HttpClient, Uri, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a HEAD request to a Uri ensuring that the operation succeeded.
Declaration
public static Task<HttpResponseMessage> HeadSafeAsync(this HttpClient client, Uri requestUri, HttpContent content = null, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
OptionsAsync(HttpClient, string, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a OPTIONS request to a string URI.
Declaration
public static Task<HttpResponseMessage> OptionsAsync(this HttpClient client, string requestUri, HttpContent content = null, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
OptionsAsync(HttpClient, Uri, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a OPTIONS request to a Uri.
Declaration
public static Task<HttpResponseMessage> OptionsAsync(this HttpClient client, Uri requestUri, HttpContent content = null, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
OptionsSafeAsync(HttpClient, string, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a OPTIONS request to a string URI ensuring that the operation succeeded.
Declaration
public static Task<HttpResponseMessage> OptionsSafeAsync(this HttpClient client, string requestUri, HttpContent content = null, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
OptionsSafeAsync(HttpClient, Uri, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a OPTIONS request to a Uri ensuring that the operation succeeded.
Declaration
public static Task<HttpResponseMessage> OptionsSafeAsync(this HttpClient client, Uri requestUri, HttpContent content = null, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
PatchAsync(HttpClient, string, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a PATCH request to a string URI.
Declaration
public static Task<HttpResponseMessage> PatchAsync(this HttpClient client, string requestUri, HttpContent content, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
PatchAsync(HttpClient, Uri, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a PATCH request to a Uri.
Declaration
public static Task<HttpResponseMessage> PatchAsync(this HttpClient client, Uri requestUri, HttpContent content, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
PatchSafeAsync(HttpClient, string, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a PATCH request to a string URI ensuring that the operation succeeded.
Declaration
public static Task<HttpResponseMessage> PatchSafeAsync(this HttpClient client, string requestUri, HttpContent content, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
PatchSafeAsync(HttpClient, Uri, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a PATCH request to a Uri ensuring that the operation succeeded.
Declaration
public static Task<HttpResponseMessage> PatchSafeAsync(this HttpClient client, Uri requestUri, HttpContent content, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
PostAsync(HttpClient, string, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a POST request to a string URI.
Declaration
public static Task<HttpResponseMessage> PostAsync(this HttpClient client, string requestUri, HttpContent content, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
PostAsync(HttpClient, Uri, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a POST request to a Uri.
Declaration
public static Task<HttpResponseMessage> PostAsync(this HttpClient client, Uri requestUri, HttpContent content, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
PostSafeAsync(HttpClient, string, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a POST request to a string URI ensuring that the operation succeeded.
Declaration
public static Task<HttpResponseMessage> PostSafeAsync(this HttpClient client, string requestUri, HttpContent content, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
PostSafeAsync(HttpClient, Uri, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a POST request to a Uri ensuring that the operation succeeded.
Declaration
public static Task<HttpResponseMessage> PostSafeAsync(this HttpClient client, Uri requestUri, HttpContent content, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
PutAsync(HttpClient, string, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a PUT request to a string URI.
Declaration
public static Task<HttpResponseMessage> PutAsync(this HttpClient client, string requestUri, HttpContent content, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
PutAsync(HttpClient, Uri, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a PUT request to a Uri.
Declaration
public static Task<HttpResponseMessage> PutAsync(this HttpClient client, Uri requestUri, HttpContent content, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
PutSafeAsync(HttpClient, string, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a PUT request to a string URI ensuring that the operation succeeded.
Declaration
public static Task<HttpResponseMessage> PutSafeAsync(this HttpClient client, string requestUri, HttpContent content, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
string | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
PutSafeAsync(HttpClient, Uri, HttpContent, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends a PUT request to a Uri ensuring that the operation succeeded.
Declaration
public static Task<HttpResponseMessage> PutSafeAsync(this HttpClient client, Uri requestUri, HttpContent content, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
Uri | requestUri | The request URI. |
HttpContent | content | The content to be sent to the server. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |
SendAsync(HttpClient, HttpRequestMessage, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends an HttpRequestMessage.
Declaration
public static Task<HttpResponseMessage> SendAsync(this HttpClient client, HttpRequestMessage request, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
HttpRequestMessage | request | The request. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
InvalidOperationException | Thrown when the request has already been sent by the HttpClient class. |
SendSafeAsync(HttpClient, HttpRequestMessage, ArgDictionary, HttpCompletionOption, CancellationToken)
Sends an HttpRequestMessage ensuring that the operation succeeded.
Declaration
public static Task<HttpResponseMessage> SendSafeAsync(this HttpClient client, HttpRequestMessage request, ArgDictionary headers = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | The client. |
HttpRequestMessage | request | The request. |
ArgDictionary | headers | Optional request headers. |
HttpCompletionOption | completionOption | Optionally specifies when the operation should complete (as soon as a response is available or after reading the whole response content). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<HttpResponseMessage> | The response. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when a required argument is |
InvalidOperationException | Thrown when the request has already been sent by the HttpClient class. |
SocketException | Thrown for network connectivity issues. |
HttpException | Thrown when the server responds with an HTTP error status code. |