How to Use cURL for HEAD Requests: A Developer's Guide
TutorialsLearn to use cURL HEAD requests. Check headers, verify status codes, and save bandwidth.

Marijus Narbutas
Key Takeaways
-
A cURL HEAD request fetches headers like content type, but the server doesn’t return the response body, significantly reducing bandwidth usage.
-
You can use the cURL HEAD method to monitor uptime by checking the response code, or add the -L flag to follow redirects and trace URLs.
-
The basic request uses curl -I (uppercase “i”), but you can add custom headers or other flags to suit your needs.
There are times when you might need to check if a file exists without downloading the whole thing, and that’s where a cURL HEAD request becomes very useful. It’s a quick way to get details from a server and see the file size or the content type instantly.
A HEAD request is unique because it explicitly instructs the server to return only the headers, omitting the response body. You get the important data, but you don’t use up your bandwidth downloading the page content.
What Is a HEAD Request?
The HEAD method is a specific type of HTTP request. It works almost exactly like a GET request , but there’s one big difference: when you send a HEAD request, the web server returns only the response headers; it does not return the response body.
It speeds up network transfers for HEAD requests compared to GET requests. You can use it to check if a page is online or see when a file was last changed.
Here is a quick comparison:
| Feature | HEAD request | GET request |
|---|---|---|
| Data fetched | Fetches response headers | Fetches headers and body |
| Transmission | Omits response body | Downloads full response body |
| Network speed | Faster and lighter | Slower and heavier |
Developers often use a HEAD request for monitoring. If the HEAD request fails to connect or times out, you know the site is down. A HEAD request is also great for checking links.
How to Use cURL for HEAD Requests
You can easily send these requests from the command line. The basic one is simple to type; all you need is the right flag.
Here is the core cURL command:
curl -I https://iproyal.com
Note: the letter is uppercase “i”, not lowercase “L”.
When you type it, you send a basic cURL HEAD request to the server. The -I flag tells the tool to perform it, and the output shows several response headers . You’ll also see the HTTP status code, which tells you if the request worked.
You might also see the content type of the file, which tells you if the link is an image, a video, or text. Another common header is the content-length, which shows the file size in bytes.
While you technically can force the method with -X HEAD, it often causes the command to hang. It’s much safer and standard practice to use -I to make a request.
It ensures you see the headers clearly, and if the status code is 200, your cURL HEAD was successful. If you see a 400 or 500-level code, there’s an error. However, a 300-level code simply means the page has moved (redirect).
How to Send Headers or Data in a cURL HEAD Request
Sometimes a server requires additional information, which you can provide by sending custom headers with your request. You can do so by using the -H flag in your cURL command.
For example, you might need to send a key to access a private page. You can add these custom headers easily. You should not use the -d flag with a HEAD request. Since -d implies a POST request , using it alongside the HEAD flag causes a conflict, and cURL will show an error.
The HEAD method doesn’t support a request body. If you need to send specific parameters, you should include them directly in the URL (e.g., ?id=10) rather than using data flags.
In short, a cURL HEAD is about fetching info. It’s not for sending large files. However, sending HTTP headers helps you access protected sites.
cURL vs Postman: Which One to Use?
cURL is a popular command-line tool (CLI), and Postman is a visual app with buttons and menus. While both can send a HEAD request, a cURL HEAD request is often faster to execute. All you need to do is just open your command line and type the cURL command.
cURL is often the better choice for server-side automation because it comes pre-installed on most systems, allowing you to run scripts without installing additional software. You can write a script to send a cURL HEAD every minute.
While Postman is excellent for visual development and organizing complex requests, a CLI like cURL is much lighter and faster for quick checks. If you need to test a HEAD request quickly, cURL is the best choice.
Use Cases for cURL HEAD Requests
There are many practical ways to use a cURL HEAD request:
- Checking file types. You can check the content type before you download. If the content type says “video/mp4”, you know it’s a video. You can also check the content type to ensure an API returns JSON.
- Tracing links. You can follow a link to its final home. If you add the -L flag, the request will follow redirects. It’s useful if a site is moved. By adding the -v flag alongside -L, you can watch the request hop from one link to another and see the full redirect path.
- Uptime monitoring. You can script a cURL HEAD request to run often. If the response code is 200 (or typically 301/302 for redirects), the site is healthy. If the code changes to 500, the web server has an error.
- Checking caches. You can inspect the cache control headers to see whether the site stores data in a cache. Checking cache control helps you debug loading issues.
- Verifying existence. You can check the Content-Length header (if present) to determine whether a file is empty. A HEAD request tells you this instantly. If the response code is 404, the file is gone.
Is cURL Safe to Use?
Yes, cURL is very safe. Millions of people use cURL requests every day. Be cautious with the --insecure (or -k) flag since it tells cURL to skip SSL certificate verification, which could expose your connection to attackers.
Only use that flag if you trust the web server. Always check the HTTP status code to ensure the connection is working. A cURL HEAD request is generally safer for probing unknown servers because it avoids downloading a potentially malicious response body.
Conclusion
A HEAD request is a powerful tool for developers that lets you inspect response headers without the weight of the response body.
It’s an essential tool for checking status codes, verifying file metadata such as content-length, and debugging server configurations, including redirects and cache headers. It’s a helpful tool for following redirects, verifying response codes, and more.