How to make a HEAD request with curl
Curl is a useful program used to perform HTTP requests.
In Curl, we can call a HEAD request in various ways, including:
- with the
-Ior--headflag - with the
-X HEADor--request HEADflag
The -I flag
In the first case, the program executes a request the same way it would with a GET request, but it will not display its body.
For example, you can have the Content-Length header without actually having a body. The program just asks for the headers and the closes the connection.
Let’s see an example:
The -X HEAD flag
In the second case, we are going to call a custom method. By default, it won’t print anything.
If we want to make a HEAD request and print the results, we need to add the -i flag.
Here is an example: