415
Client Error
415 Unsupported Media Type: Wrong ContentβType
β¦ The Golden Answer: The 415 Unsupported Media Type status code means the server refuses to accept the request because the payload format (Content-Type header) is not supported. The server is telling the client: "I understand the request, but I cannot process the data format you sent." This is a common issue in API development when the client sends JSON but the server expects XML, or vice versa.
Common Causes of 415 Errors
| Cause | Example | How to Fix |
|---|---|---|
| Wrong Content-Type header | Sending application/xml but server expects application/json. | Set the correct Content-Type header in your request. |
| Missing Content-Type | Client sends a body without a Content-Type header. | Always include a Content-Type header for requests with a body. |
| Server doesn't support the format | Server only supports JSON, client sends multipart/form-data. | Check API documentation for supported formats and use one of them. |
| Incorrect charset | application/json; charset=windows-1252 but server expects UTFβ8. | Use charset=utf-8 or omit the charset. |
| CDN or proxy stripping headers | An intermediate system removes or alters the Content-Type. | Check proxy logs and ensure headers are preserved. |
Example: 415 Response
A client sends a POST with application/xml but the server only accepts JSON:
POST /api/users HTTP/1.1
Host: example.com
Content-Type: application/xml
<user><name>John</name></user>
HTTP/1.1 415 Unsupported Media Type
Content-Type: application/json
{
"error": "Unsupported media type. Please use application/json."
}
415 vs. 406 Not Acceptable
| Status | Direction | Meaning |
|---|---|---|
| 415 Unsupported Media Type | Request β Server | The Content-Type of the request body is not supported. |
| 406 Not Acceptable | Server β Client | The server cannot produce a response format that the client accepts (via Accept header). |
How to Fix 415 Errors
- If you're a client developer: Check the API documentation for the required
Content-Type. Set the header correctly. For JSON APIs, useContent-Type: application/json. For form data, useContent-Type: multipart/form-dataorapplication/x-www-form-urlencoded. - If you're a server developer: Ensure your server accepts the formats you advertise. If you're using a framework like Express, Flask, or Spring, configure the supported media types explicitly. Send a helpful error message indicating which formats are supported.
- If you're an endβuser: This error is almost always due to an application bug. Contact the developer or support team.
Common Media Types
application/jsonβ JSON data.application/xmlβ XML data.application/x-www-form-urlencodedβ HTML form data (key=value pairs).multipart/form-dataβ file uploads and mixed data.text/plainβ plain text.application/octet-streamβ binary data.
Always consult your API documentation to know which media types are supported.
Frequently Asked Questions
Is 415 a client error or a server error?
It's a client error (4xx) because the client sent a request with an unsupported media type. The server is working correctly but cannot process the client's data format.
What is the difference between Content-Type and Accept headers?
Content-Type tells the server what format the request body is in. Accept tells the server what format the client wants the response in. Both are essential for proper content negotiation.
Can I send multiple media types in the Content-Type header?
No, Content-Type should specify exactly one media type. If you need to send multiple formats, you should use a single format that can encapsulate the others (e.g., multipart/mixed).