The command
curl https://httpbin.org/post \
-H "Content-Type: application/json; charset=utf-8" \
-d '{"city":"Zürich"}'
Opens the request console with this request filled in. It is sent from api-tester.com's server rather than from your machine, so it shows what the endpoint returns, not how your own network or curl build behaves.
What the flags do
| Flag | What it does |
|---|---|
-d / --data-binary | Default type application/x-www-form-urlencoded, whatever the data is. |
--json | Sets application/json. |
-F | Sets multipart/form-data; boundary=.... Leave it alone. |
-T | Sets no Content-Type at all. |
-H "Content-Type: ..." | Overrides any of the above. |
What curl sends by default
The default comes from the flag, not from the content. Curl does not look inside the body, so a JSON string given to -d is announced as a form, and a PNG sent with --data-binary is too. The server then runs the wrong parser and reports an empty or malformed body, or refuses outright with 415 Unsupported Media Type.
Set the header explicitly whenever the body is anything other than form fields.
curl -d '{"a":1}' https://httpbin.org/post # says form — wrong
curl -d '{"a":1}' -H "Content-Type: application/json" https://httpbin.org/post
curl --data-binary @data.csv -H "Content-Type: text/csv" https://httpbin.org/post
Charset and parameters
A media type can carry parameters after a semicolon. charset=utf-8 is the common one; it matters for text formats such as text/plain, text/csv and XML. JSON is defined as UTF-8 already, so the parameter is redundant there, though harmless and often expected by older servers.
Check what was really sent with -v, and remember that Content-Type on the response is a separate header describing what came back.
curl -v -o /dev/null -d "note=hi" https://httpbin.org/post 2>&1 | grep -i "^> content-type"
Common mistakes
Content-Typeon a GET is meaningless. To choose the response format, sendAccept.- Overriding the type on a
-Frequest deletes the boundary and breaks the upload. - Typos fail silently.
application/jsnois a valid-looking header that no server will parse as JSON.
Related curl examples
Curl Send Header Example
-H adds a header line to the request.
Curl POST JSON Example
Sending JSON takes two things: the JSON itself and a header saying that is what it is.
Curl POST XML Example
XML over HTTP works like JSON over HTTP with different media types, plus one extra header if the service speaks SOAP.
Curl POST Form Example
HTML forms post in one of two encodings, and curl has a flag for each.
MIME Types
A list of the media types that go in Content-Type and Accept.
All Curl Examples
49 worked examples, grouped by what you are trying to do.
More under Headers
References
- curl man page: -H — Overriding the Content-Type curl would otherwise send.
- MDN: Content-Type — Syntax, parameters such as charset, and common values.
These links leave api-tester.com, which is independent of the projects they point to.
FAQ
How do I set the Content-Type header in curl?
Add -H "Content-Type: type/subtype", for example -H "Content-Type: application/json". It overrides the type curl would send by default.
What is the default Content-Type in curl?
application/x-www-form-urlencoded when a body is sent with -d or --data-binary, application/json with --json, and multipart/form-data with -F. Requests without a body have none.
How do I fix 415 Unsupported Media Type with curl?
Set the Content-Type header to the media type the API expects for the body you are sending, most often application/json.