Table of Contents
In this article we will show you how to send HTTP header with Curl request. You can use the -H command-line option and pass the header name and value in “Key: Value” style to send an HTTP header with a Curl request. If you don’t give a value for the header, the normal header that Curl would send will be taken out.
You can have as many HTTP headers as you want. You can add as many tags as you need to a Curl request. Curl is a programme that lets people send network requests from the command line. Curl works on Windows, Linux, and Mac, which makes it the most popular choice for developers on all systems. Curl is an open-source tool for transferring data to and from a computer.
It is run from the command line. It is very flexible and works with many different protocols, such as HTTP, FTP, SMTP, and many others. It is usually used to test APIs and communicate with them, download files, and do other tasks that involve communicating over a network.
How to send HTTP header with Curl request
- 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 https://httpbin.scrapingbee.com/headers?json \
-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": "httpbin.scrapingbee.com", "User-Agent": "curl/7.86.0" } }
- You can also pass several headers by using the -H option multiple times:
curl https://httpbin.scrapingbee.com/headers?json \
-H "custom-header: custom-value" \
-H "another-header: another-value"
What is Curl?
Curl, which stands for “Client URL,” is a famous command-line tool that lets you send and receive data to and from a server using HTTP, HTTPS, and FTP, among others. With the Curl project tool (libcurl), developers can make HTTP requests right from their apps. Curl runs on Linux, Windows, and the macOS platform.
What is HTTP Header?
HTTP headers are pairs of keys and values that send extra information from the client to the server. With HTTP, the headers are used to send and receive data. When sending HTML forms, the client can use HTTP headers to send information like the User-Agent name, the list of languages that are allowed, and the data type in the body of the request message.
In turn, the server uses HTTP headers to tell the client the amount and type of data in the response body, as well as the compression method, caching directives, and CORS headers.