Curl/Bash code for Curl Send Header ExampleThis Curl/Bash code snippet was generated automatically for the Curl Send Header example.
<< Back to the Curl Send Header example
What is Curl?
Curl (stands for Client URL) is a popular command-line tool that you can use to transfer data to/from a server using a range of network protocols, including HTTP, HTTPS, and FTP. Developers can use the Curl project library (libcurl) to make HTTP requests directly from their applications. Curl works on platforms Linux, Windows, and macOS.
What is HTTP Header?
HTTP Headers are key/value pairs that pass additional data between the client and the server. In HTTP, the headers are used to transfer data in both directions. The client can use HTTP headers to send data such as the User-Agent name, the list of supported languages, and the data type in the body of the request message when submitting HTML forms. In turn, the server uses HTTP headers to tell the client the size and type of data in the response body, the compression method used, caching directives, and CORS headers.
Can I send custom HTTP headers using Curl?
Yes, you can add any custom HTTP header to your Curl request using the -H command-line option and send it to the server. Before 2011, it was recommended to name custom HTTP headers with the X- prefix to emphasize that a non-standard HTTP header is being used. However, this recommendation was deprecated in June 2012, and RFC 6648 now specifies that creators of new header parameters SHOULD NOT prefix the header names with “X-” or similar prefixes.
Can I send Curl headers with HTTP POST request?
Yes, you can send any number of additional HTTP headers with a POST request. For example, when sending JSON to the server, you can specify the data type in the request body using the Content-Type: application/json header and tell the server that the Curl client is expecting JSON using Accept: application/json". If you do not pass these additional headers with a Curl POST request, the server may misinterpret the request data or return a response in a different format.
Can I only get HTTP headers using Curl?
Yes, the -I or --head Curl command-line option allows you to fetch HTTP headers only from the server by sending an HTTP HEAD request. The HEAD request method is identical to the GET method, except that in HEAD, the server does not return the message body.
Custom Curl Headers Example
An example of sending JSON data to a server with additional Accept and Content-Type HTTP headers.
How to print request headers using Curl?
You can use the -v or --verbose command-line argument to view the request headers. This will print a lot of debugging information about how Curl makes the request, including the HTTP headers sent to the server and received from the server.
How to pass multiple headers to Curl?
To pass multiple headers in a Curl request, use the -H command-line argument as many times as you need.
How can I remove the standard request header from a Curl request?
To remove the default HTTP header from the Curl request, such as the User-Agent name, add the HTTP header name with no value using the -H command-line option.
How to print server response headers using Curl?
The -i or --include command-line argument tells Curl to print HTTP response headers in its output. HTTP response headers usually contain information such as the MIME type and size of the resource in the HTTP message body, a list of cookies, caching instructions, etc.