Site icon JD Bots

How to Send a Header with curl

Card titled Send a Header with curl, labelled shell basics, with three ticked lines: the option -H X-Greeting: hello, and the sent request lines Host: example.com and X-Greeting: hello.

A header is a name and a value sent along with a web request, such as an API key. curl -H adds one to the request curl sends.

Every command and output on this page is real, run in Terminal with the curl that comes with macOS 26 (curl 8.7.1).

Syntax

Syntax

curl -H "Name: value" URL

See -H, --header in the curl manual.

The Example

A request to example.com, a domain kept for examples, with the header X-Greeting: hello. -v makes curl print the request it sends.

Step 1: Send the Request

Terminal

curl -v -H "X-Greeting: hello" https://example.com/

Output (the lines that matter)

> GET / HTTP/2
> Host: example.com
> User-Agent: curl/8.7.1
> Accept: */*
> X-Greeting: hello

Lines that start with > are the request curl sent: its own headers, then yours on the last line. The page’s HTML follows after them.

Common Mistakes

MistakeWhat happensDo this instead
Leaving out the colon: -H "X-Greeting hello"curl doesn’t send the header at all: no X-Greeting line among the > linesWrite a colon after the name: X-Greeting: hello

FAQ

How do I send an API key with curl?

Many APIs read the key from a header, so send it with -H, such as -H "X-N8N-API-KEY: your-key" for n8n’s API.

Conclusion

Add -H "Name: value" for each header, and use -v to see what curl really sent.

Additional Resources

macOS is a trademark of Apple Inc.

Exit mobile version