In this short article, we are going to show how to prepare an HTTP request with one and many headers using curl.
-H --header parameter
According to curl manual page:
-H --header parameter sets additional header to provide with the request when communicating through HTTP with a server. Any number of additional headers may be specified.
3. Set single HTTP header with curl
To set a single HTTP header simply use curl with
--header parameter with a value in format:
[HEADER NAME]:[HEADER VALUE] like in the following example:
In this example, we set one header with X-Custom-Header name and 123 value.
4. Set multiply headers using curl
Use more than one
-H --header parameter if you wish to send several headers. The curl will parse each as a distinct header.
In this example we will send two headers:
- Accept: application/json - to notify server we will accept JSON data,
- Content-Type: application/json - use to inform the server site that we will send data in JSON format.
In this short article, we present how to set headers with HTTP requests using the curl tool.