How to send HTTP header using cURL?

To send HTTP header using cURL you just have to use the -H command line option with the header name and value. Here is a sample command that sends a GET request to our hosted version of HTTPBin with a custom HTTP header:

curl \
   -H "custom-header: custom-value"

And since this particular URL returns the headers sent to the server in JSON format, the response will be:

  "headers": {
    "Custom-Header": "custom-value",
    "Host": "",
    "User-Agent": "curl/7.86.0"

You can also pass several headers by using the -H option multiple times:

curl \
   -H "custom-header: custom-value" \
   -H "another-header: another-value"

What is cURL?

cURL is an open-source command-line tool used to transfer data to and from a server. It is extremely versatile and supports various protocols including HTTP, FTP, SMTP, and many others. It is generally used to test and interact with APIs, download files, and perform various other tasks involving network communication.

What is an HTTP header?

An HTTP header is a set of key-value pairs that are sent as part of an HTTP request or response. HTTP headers are used to send additional information about the request or the response, such as the browser type, the content type, the length of the content, cookies, authentication information, and many others.

Related curl web scraping questions: