How to Send Multiple Headers in a Curl Request
When making HTTP requests using the command-line tool curl, you often need to pass multiple distinct metadata headers to authorize or configure the request properly. This article provides a direct guide on how to send multiple headers in a single curl command, detailing the exact syntax and providing practical examples for immediate use.
To send multiple distinct headers in a single curl request, you must
use the -H (or --header) option multiple times
within the same command. Each individual header requires its own
-H flag followed by the “Header-Name: Value” pair enclosed
in quotes.
Command Syntax
The basic syntax for adding multiple headers to a curl request is as follows:
curl -H "Header-Name-1: Value-1" -H "Header-Name-2: Value-2" -H "Header-Name-3: Value-3" [URL]Practical Example
If you want to send a GET request to an API that requires both an authorization token and a specific content type, your curl command would look like this:
curl -H "Authorization: Bearer your_token_here" -H "Accept: application/json" https://api.example.com/dataIn this command: *
-H "Authorization: Bearer your_token_here" sends the first
header. * -H "Accept: application/json" sends the second
header.
You can append as many -H flags as your destination
server requires. Curl will package all specified headers together and
send them in a single, unified HTTP request.