Skip to content
CheckcraftDownload
Practical workflow

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.

Checkcraft ·

Get help with your first test →

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.

API call diagram: method and URL, headers, body, status and response body, logs and database

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
Layers of an API call check: status, headers, body, calculations, logs, database

What the server answers without the right header

ResponseCommon cause
415 Unsupported Media TypeNo Content-Type: application/json or a form type
400 Bad RequestThe body did not parse as JSON due to quotes or type
406 Not AcceptableAccept asks for a format the server does not serve
HTML instead of JSONNo 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.

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.

Next step

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 run

No sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.

References

curl man page

Start with the linked example and compare its result with your own test requirement.

Ask a person

Get help with your first test

Tell us what you want to test or where you got stuck. We can help you start Checkcraft, choose an example and understand your first run. You can ask before downloading.

The Telegram group is public: do not post passwords, tokens or confidential work data. A description of your task is enough to start.

You can also email us support@checkcraft.ru

No account required. We will reply by email. This is a support request, not a newsletter subscription.