Methods
Abort
Aborts all requests on this instance
C#httpClient.Abort();
Delete
Sends a DELETE request to the specified Uri and returns the response. Data to be sent is specified as an IHttpContent, the available types are detailed here
Without content
C#httpClient.Delete(new Uri("http://httpbin.org/delete"), HttpCompletionOption.AllResponseContent, (r) =>
{
// Raised either when the download completes or periodically depending on the HttpCompletionOption
});
// or
var response = await httpClient.DeleteAsync(new Uri("http://httpbin.org/delete"));
With content
C#httpClient.Delete(new Uri("http://httpbin.org/delete"), new StringContent("Hello World"), HttpCompletionOption.AllResponseContent, (r) =>
{
// Raised either when the download completes or periodically depending on the HttpCompletionOption
}, (u) =>
{
// Raised periodically when uploading, this callback does not need to be specified
});
// or
var response = await httpClient.DeleteAsync(new Uri("http://httpbin.org/delete"), new StringContent("Hello World"));
Get
Sends a GET request to the specified Uri and returns the response
C#httpClient.Get(new Uri("http://httpbin.org/get"), HttpCompletionOption.AllResponseContent, (r) =>
{
// Raised either when the download completes or periodically depending on the HttpCompletionOption
});
// or
var response = httpClient.GetAsync(new Uri("http://httpbin.org/get"));
Patch
Sends a PATCH request to the specified Uri and returns the response. Data to be sent is specified as an IHttpContent, the available types are detailed here
C#httpClient.Patch(new Uri("http://httpbin.org/patch"), new StringContent("Hello World"), HttpCompletionOption.AllResponseContent, (r) =>
{
// Raised either when the download completes or periodically depending on the HttpCompletionOption
}, (u) =>
{
// Raised periodically when uploading, this callback does not need to be specified
});
// or
var response = await httpClient.PatchAsync(new Uri("http://httpbin.org/patch"), new StringContent("Hello World"));
Post
Sends a POST request to the specified Uri and returns the response. Data to be sent is specified as an IHttpContent, the available types are detailed here
C#httpClient.Post(new Uri("http://httpbin.org/post"), new StringContent("Hello World"), HttpCompletionOption.AllResponseContent, (r) =>
{
// Raised either when the download completes or periodically depending on the HttpCompletionOption
}, (u) =>
{
// Raised periodically when uploading, this callback does not need to be specified
});
// or
var response = await httpClient.PostAsync(new Uri("http://httpbin.org/post"), new StringContent("Hello World"));
Put
Sends a PUT request to the specified Uri and returns the response. Data to be sent is specified as an IHttpContent, the available types are detailed here
C#httpClient.Put(new Uri("http://httpbin.org/put"), new StringContent("Hello World"), HttpCompletionOption.AllResponseContent, (r) =>
{
// Raised either when the download completes or periodically depending on the HttpCompletionOption
}, (u) =>
{
// Raised periodically when uploading, this callback does not need to be specified
});
// or
var response = await httpClient.PutAsync(new Uri("http://httpbin.org/put"), new StringContent("Hello World"));
Send
Use Send if you need more control over the request, for example including headers only for this request. If duplicate headers exist between the HttpClient instance and the request then the request header will take precedence
C#var message = new HttpRequestMessage()
{
Uri = new Uri("http://httpbin.org/post"),
Method = HttpAction.Get,
Content = new StringContent("Hello World")
};
message.Headers.Add("SomeHeader", "SomeValue");
httpClient.Send(message, HttpCompletionOption.AllResponseContent, (r) =>
{
// Raised either when the download completes or periodically depending on the HttpCompletionOption
}, (u) =>
{
// Raised periodically when uploading, this callback does not need to be specified
});
// or
var response = httpClient.SendAsync(message);