Headers in curl: Content-Type application/json, Accept and multiple -H
Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. Download, no sign-up →
Headers in curl are set with -H, one per header. The most common mistake is sending JSON without Content-Type: application/json. Then curl with -d sets the form type and the server cannot parse the body. Below is how to write headers properly and check what was sent.
Content-Type and Accept
Content-Type tells the server the request body format. Accept tells it which response format you expect. JSON APIs usually need both. With -d and no Content-Type, curl sends application/x-www-form-urlencoded.
The --json flag
curl 7.82 and newer has --json: it sends the body like -d and sets Content-Type and Accept to application/json. Shorter, but older curl builds lack it, so instructions for a team are safer with explicit headers.

How to see sent headers
-v prints the whole request: lines with a greater-than sign are what went to the server. Two Content-Type lines or a form type instead of JSON mean the server rightly could not read it. An empty value after the colon in -H removes a header curl adds itself.
Commands with headers
# JSON с явными заголовками
curl -X POST https://api.example.com/v1/orders \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"sku":"MON-24","qty":2}'
# то же короче, curl 7.82+
curl --json '{"sku":"MON-24","qty":2}' https://api.example.com/v1/orders
# несколько своих заголовков
curl https://api.example.com/v1/orders \
-H "Authorization: Bearer $TOKEN" \
-H "X-Request-Id: test-001" \
-H "Accept-Language: ru"
# убрать заголовок, который curl ставит сам
curl -H "User-Agent:" https://api.example.com/v1/orders
What the server answers without the right header
| Response | Common cause |
|---|---|
| 415 Unsupported Media Type | No Content-Type: application/json or a form type |
| 400 Bad Request | The body did not parse as JSON due to quotes or type |
| 406 Not Acceptable | Accept asks for a format the server does not serve |
| HTML instead of JSON | No Accept: application/json, the server sent a page |
On Windows quotes inside JSON often get lost, causing 400: curl on Windows and PowerShell.
More on curl
Section overview and all guides: curl command cheat sheet: flags and examples for APIs.
- curl with authorization: Bearer token, Basic, API key and headers
- curl errors: codes 6, 7, 22, 28, 35, 60 and how to fix them
- curl on Windows and PowerShell: how to run it and why commands fail
- Download a file with curl: -o, -O, redirects and resume
- curl through a proxy: -x, environment variables, SOCKS and no_proxy
Frequently asked questions
How do I set Content-Type application/json?
-H "Content-Type: application/json", or --json on curl 7.82+.
How do I pass several headers?
Repeat -H for each.
Why 415?
No Content-Type or a form type: -d alone sends application/x-www-form-urlencoded.
Repeat this on your own API
Checkcraft is a desktop app that saves API response checks without code and shows what did not match. Start with a sample, then use your own sanitized data. Free runs on Windows and Linux with no time limit.
Download FreeDownload and first runNo sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.
References
Start with the linked example and compare its result with your own test requirement.