What 415 Means
A request with a body (POST, PUT, PATCH) carries a Content-Type header that says what the body is: JSON, form data, XML, a file. The endpoint accepts only certain types. If the header names a type it does not handle, or is missing, the server answers 415 Unsupported Media Type before it reads the content.
The same code can also mean the server does not support the body's Content-Encoding, for example a compressed body the endpoint cannot unpack.
Common Causes
- No Content-Type at all: the body is JSON, but nothing tells the server.
- Form data where JSON is expected: curl's
-dsendsapplication/x-www-form-urlencodedunless you set the header. - JSON where form data or a file upload is expected: upload endpoints often want
multipart/form-data. - A plain string body: some HTTP clients label a string body as
text/plain. - A strict charset match: a few servers reject
application/json; charset=utf-8and accept only the bare type, or the other way round. - Compressed body: a
Content-Encoding: gziprequest to a server that does not decompress requests.
Fix It with curl
The request that often fails:
curl -i -X POST https://api.example.com/v1/items \
-d '{"name":"Desk lamp"}'
The same request with the type declared:
curl -i -X POST https://api.example.com/v1/items \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"name":"Desk lamp"}'
curl 7.82.0 and later also have --json, which sets both headers and sends the data. For an upload endpoint, curl's -F option sends the body as multipart/form-data instead. More request examples are in curl POST request.
Read What the Server Accepts
Check the endpoint's documentation for the expected type. Some servers also add an Accept or Accept-Post header to the 415 response listing the types they take, or Accept-Encoding when the encoding was the problem; curl -i shows it. The body of the response often names the type that was refused.
415 Compared with 406
| Code | About | Header involved |
|---|---|---|
| 415 | What you send | Content-Type |
| 406 | What you ask back | Accept |
A 406 means the server cannot answer in any format your Accept header allows; see 406 Not Acceptable. When the type is right but the data inside fails validation, the answer is 422 instead: see 422 Unprocessable Content.
Checks on the Server Side
- Application log: the framework usually logs the content type it refused. The web server only passes the code through.
- Route configuration: the endpoint may be declared to consume one type only; add the type you want to support.
- A proxy that changes headers: a rule that removes or rewrites
Content-Typeon the way in causes 415 for every client. - A web application firewall: some rule sets block unusual content types before the application sees them.
From a Web Page
If a script on your own site gets 415 from your API, set the Content-Type header explicitly in the request and send the body as a JSON string. Check the request in the browser's developer tools, under the network panel, to see which type was actually sent.