Skip to content
shellhacks.dev
APIs

Send a custom header

Send a custom request header with curl -H 'Name: value'. A header with an empty value after a colon removes one of curl's defaults, such as User-Agent.

1 min read
Summarize in AI

An API wants an extra header, such as a request id, and you want to see exactly which headers curl put on the wire.

Shell
curl -sv -H 'X-Request-Id: abc123' http://127.0.0.1:8000/index.txt -o /dev/null 2>&1 | grep '^>'
echo ---
curl -sv -H 'User-Agent:' -H 'Accept:' http://127.0.0.1:8000/index.txt -o /dev/null 2>&1 | grep '^>'
Text
> GET /index.txt HTTP/1.1
> Host: 127.0.0.1:8000
> User-Agent: curl/7.88.1
> Accept: */*
> X-Request-Id: abc123
>
---
> GET /index.txt HTTP/1.1
> Host: 127.0.0.1:8000
>

Each -H adds one header line, and -v prints the request curl sent, with lines marked by a greater-than sign. A header name followed by a colon and no value tells curl to remove that header from its defaults, so the second run sends neither User-Agent nor Accept. The rules are in the curl manual, and a header ending in a semicolon, as in -H 'X-Empty;', sends the name with an empty value.

A header you set replaces curl's own of the same name, but not one added by a library or a proxy between you and the server. The output here is from curl 7.88 on Debian 12, and the default User-Agent string changes with the version.

Taggedcurlhttp
Share

More snippets

APIs

Show only the response headers

Show only the response headers with curl, either by sending a HEAD request or by dumping the headers of a real GET with -D - and dropping the body.

1 min read
APIs

Save a download with its remote name

Save a download under the name in the URL with curl -O. It writes to the current directory, and a URL that ends in a slash has no name to use.

1 min read

Get new posts by email

One email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.