Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

curl
communitycreator

How to make a HEAD request with curl

Dario Vincenzo Tarantini

Curl is a useful program used to perform HTTP requests.

In Curl, we can call a HEAD request in various ways, including:

  • with the -I or --head flag
  • with the -X HEAD or --request HEAD flag

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:

Terminal 1
Terminal

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:

Terminal 1
Terminal

RELATED TAGS

curl
communitycreator

CONTRIBUTOR

Dario Vincenzo Tarantini
RELATED COURSES

View all Courses

Keep Exploring