How to Force Curl to Send HEAD Request

This article explains how to use the curl command-line tool to send an HTTP HEAD request to retrieve only the response headers from a web server. You will learn the primary commands to fetch headers, the difference between the available options, and how to combine flags for advanced use cases like following redirects or silencing the output.

The Standard Method: Use the -I Option

The most efficient and common way to send a HEAD request with curl is by using the -I (or --head) option. This flag tells curl to fetch the headers only and immediately terminate the connection without downloading the response body.

To use this method, run the following command in your terminal:

curl -I https://example.com

How It Works:


The Alternative Method: Use -X HEAD

Another way to send a HEAD request is by explicitly defining the request method using the -X (or --request) option.

curl -X HEAD https://example.com

Why -I is Preferred Over -X HEAD:

While curl -X HEAD changes the HTTP method to HEAD, it does not automatically tell curl to only output headers. In some configurations, curl might sit waiting for a response body that will never arrive because a HEAD request tells the server not to send one. Therefore, using the -I flag is the safer and standard approach for retrieving headers.


Useful Command Variations

You can combine the -I flag with other curl options to customize your output.

1. Follow Redirects (-L)

If the URL you are requesting redirects to another page, curl will only show the headers for the initial redirect by default. To follow the redirects and see the headers of the final destination, add the -L flag:

curl -IL https://example.com

2. Silent Mode (-s)

By default, curl may display a progress meter. To hide the progress meter and only output the HTTP headers, combine -I with the silent -s flag:

curl -Is https://example.com