Class HttpClientExtensions
Extensions for the HttpClient class
Inheritance
Namespace:Dapplo.HttpExtensions
Assembly:Dapplo.HttpExtensions.dll
Syntax
public class HttpClientExtensions
Methods
| Improve this Doc View SourceAddDefaultRequestHeader(HttpClient, String, String)
Add default request header without validation
Declaration
public static HttpClient AddDefaultRequestHeader(HttpClient client, string name, string value)
Parameters
Type | Name | Description |
---|---|---|
System.Net.Http.HttpClient | client | HttpClient |
System.String | name | Header name |
System.String | value | Header value |
Returns
Type | Description |
---|---|
System.Net.Http.HttpClient | HttpClient for fluent usage |
DeleteAsync<TResponse>(HttpClient, Uri, CancellationToken)
Send a Delete request to the server
Declaration
public static Task<TResponse> DeleteAsync<TResponse>(HttpClient httpClient, Uri uri, CancellationToken token = null)where TResponse : class
Parameters
Type | Name | Description |
---|---|---|
System.Net.Http.HttpClient | httpClient | HttpClient |
System.Uri | uri | Uri to send the delete request to |
System.Threading.CancellationToken | token | CancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<TResponse> | TResult |
GetAsAsync<TResponse>(HttpClient, Uri, CancellationToken)
Get the content from the specified uri via the HttpClient read into a Type object Currently we support Json objects which are annotated with the DataContract/DataMember attributes We might support other object, e.g MemoryStream, Bitmap etc soon
Declaration
public static Task<TResponse> GetAsAsync<TResponse>(HttpClient client, Uri uri, CancellationToken token = null)where TResponse : class
Parameters
Type | Name | Description |
---|---|---|
System.Net.Http.HttpClient | client | HttpClient |
System.Uri | uri | URI |
System.Threading.CancellationToken | token | CancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<TResponse> | the deserialized object of type T or default(T) |
HeadAsync(HttpClient, Uri, CancellationToken)
Retrieve only the content headers, by using the HTTP HEAD method
Declaration
public static Task<HttpContentHeaders> HeadAsync(HttpClient httpClient, Uri uri, CancellationToken token = null)
Parameters
Type | Name | Description |
---|---|---|
System.Net.Http.HttpClient | httpClient | |
System.Uri | uri | Uri to get HEAD for |
System.Threading.CancellationToken | token | CancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Net.Http.Headers.HttpContentHeaders> | HttpContentHeaders |
PostAsync(HttpClient, Uri, Object, CancellationToken)
Post the content, and don't expect (ignore) the response
Declaration
public static Task PostAsync(HttpClient httpClient, Uri uri, object content, CancellationToken token = null)
Parameters
Type | Name | Description |
---|---|---|
System.Net.Http.HttpClient | httpClient | HttpClient |
System.Uri | uri | Uri to post an empty request to |
System.Object | content | Content to post |
System.Threading.CancellationToken | token | CancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
PostAsync<TResponse>(HttpClient, Uri, Object, CancellationToken)
Post the content, and get the reponse
Declaration
public static Task<TResponse> PostAsync<TResponse>(HttpClient httpClient, Uri uri, object content, CancellationToken token = null)where TResponse : class
Parameters
Type | Name | Description |
---|---|---|
System.Net.Http.HttpClient | httpClient | HttpClient |
System.Uri | uri | Uri to post request to |
System.Object | content | Content to post |
System.Threading.CancellationToken | token | CancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<TResponse> | TResult |
PutAsync<TResponse>(HttpClient, Uri, Object, CancellationToken)
Put the content, and get the reponse
Declaration
public static Task<TResponse> PutAsync<TResponse>(HttpClient httpClient, Uri uri, object content, CancellationToken token = null)where TResponse : class
Parameters
Type | Name | Description |
---|---|---|
System.Net.Http.HttpClient | httpClient | HttpClient |
System.Uri | uri | Uri to put the request to |
System.Object | content | Content to put |
System.Threading.CancellationToken | token | CancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<TResponse> | TResult |
SetAuthorization(HttpClient, String, String)
Set Authorization for the current client
Declaration
public static HttpClient SetAuthorization(HttpClient client, string scheme, string authorization)
Parameters
Type | Name | Description |
---|---|---|
System.Net.Http.HttpClient | client | HttpClient |
System.String | scheme | scheme |
System.String | authorization | value |
Returns
Type | Description |
---|---|
System.Net.Http.HttpClient | HttpClient for fluent usage |
SetBasicAuthorization(HttpClient, String, String)
Set Basic Authentication for the current client
Declaration
public static HttpClient SetBasicAuthorization(HttpClient client, string user, string password)
Parameters
Type | Name | Description |
---|---|---|
System.Net.Http.HttpClient | client | HttpClient |
System.String | user | username |
System.String | password | password |
Returns
Type | Description |
---|---|
System.Net.Http.HttpClient | HttpClient for fluent usage |
SetBasicAuthorization(HttpClient, Uri)
Use the UserInfo from the Uri to set the basic authorization information
Declaration
public static HttpClient SetBasicAuthorization(HttpClient client, Uri uri)
Parameters
Type | Name | Description |
---|---|---|
System.Net.Http.HttpClient | client | HttpClient |
System.Uri | uri | Uri with UserInfo |
Returns
Type | Description |
---|---|
System.Net.Http.HttpClient | HttpClient for fluent usage |
SetBearer(HttpClient, String)
Set Bearer "Authentication" for the current client
Declaration
public static HttpClient SetBearer(HttpClient client, string bearer)
Parameters
Type | Name | Description |
---|---|---|
System.Net.Http.HttpClient | client | HttpClient |
System.String | bearer | Bearer for the authorization |
Returns
Type | Description |
---|---|
System.Net.Http.HttpClient | HttpClient for fluent usage |