HTTP HEAD request with HttpClient in .NET 4.5 and C
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
An HTTP HEAD request is the right tool when you want metadata about a resource without downloading the body. In .NET 4.5, HttpClient can send HEAD requests just fine, but you do it through HttpRequestMessage and SendAsync because there is no built-in HeadAsync helper.
Build the Request Explicitly
The key idea is simple: create a request object, set the method to HEAD, and send it with HttpClient.
That is all a HEAD request really is in HttpClient. The server receives the same target URL and most of the same headers as a GET, but it should return only response headers.
Use HEAD When Headers Are the Real Goal
A common mistake is sending GET and then ignoring the body. If you only need metadata such as Content-Length, Last-Modified, or ETag, HEAD communicates the intent better and can avoid unnecessary transfer work.
ResponseHeadersRead is a good fit here because headers are the only interesting part of the response.
Wrap It in a Reusable Helper
In application code, the caller usually wants an answer such as "does this file exist" or "what is the remote size." A small helper keeps the rest of the code cleaner.
This keeps HEAD logic, status handling, and header parsing in one place. It also makes testing easier because the code that consumes the helper no longer needs to understand the entire HTTP exchange.
Be Ready for Servers That Mishandle HEAD
Although HEAD is part of HTTP, some servers do not implement it properly. A few return 405 Method Not Allowed, and others respond without the headers you expected. If you know you must talk to such an endpoint, a deliberate fallback to GET may be necessary.
That fallback should be intentional, not automatic cargo cult. A GET may begin a large body transfer immediately, so you are changing both performance and semantics.
Reuse HttpClient Correctly
Even in .NET 4.5, you should avoid constructing a fresh HttpClient for every single probe inside a long-running process. Reusing the client usually gives better connection behavior and fewer resource surprises. It is also wise to set an explicit timeout that matches the job.
For a service that performs many metadata checks, one long-lived client per logical service boundary is a sensible default.
Common Pitfalls
- Trying to call a nonexistent
HeadAsyncmethod instead of usingHttpRequestMessage. - Sending
GETwhen the real requirement is only headers. - Assuming every upstream server handles
HEADcorrectly. - Creating a new
HttpClientfor every probe in a loop. - Checking only the status code and forgetting to inspect whether required headers are actually present.
Summary
- In .NET 4.5, send
HEADby creating anHttpRequestMessageand usingSendAsync. - Use
HEADwhen you need metadata but not the response body. - Read values such as
Content-Length,Last-Modified, andETagfrom the response headers. - Add a fallback only if you know the target server mishandles
HEAD. - Reuse
HttpClientand set explicit timeouts in real applications.
Related reading
- HTTP POST Returns Error 417 Expectation Failed.
- HTTP POST using JSON in Java
- HTTP Request in Swift with POST method
- HTTP requests and JSON parsing in Python
- HttpClient single instance with different authentication headers
- HttpClient To Get List With Async/Await Operation
- HTTP Requests in an AWS Lambda
- HTTP response code for POST when resource already exists

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.