The Wavelength The Wavelength -4 years ago 160
C# Question

HTTP HEAD request with HttpClient in .NET 4.5 and C#

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
.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download