Is it possible to create a HTTP HEAD request with the new HttpClient in .NET 4.5? The only methods I can find are GetAsync, DeleteAsync, PutAsync and PostAsync. I know that the HttpWebRequest-class is able to do that, but I want to use the modern HttpClient.
To make a HEAD request with Curl, you need to use the -I or --head command-line parameter. The -I command-line parameter tells Curl to send an HTTP HEAD request to receive only HTTP headers. The HEAD request is very similar to a GET request, except that the server only returns HTTP headers without a response body.
HttpClient class provides a base class for sending/receiving the HTTP requests/responses from a URL. It is a supported async feature of . NET framework. HttpClient is able to process multiple concurrent requests.
HEAD Http Method HEAD is a request method supported by HTTP used by the World Wide Web. The HEAD method asks for a response identical to that of a GET request, but without the response body. This is useful for retrieving meta-information written in response headers, without having to transport the entire content.
Use the SendAsync method with an instance of HttpRequestMessage that was constructed using HttpMethod.Head .
GetAsync, PostAsync, etc are convenient wrappers around SendAsync; the less common HTTP methods such as HEAD, OPTIONS, etc, don't get a wrapper.
In short:
client.SendAsync(new HttpRequestMessage(HttpMethod.Head, url))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With