415 Unsupported Media Type
Client Error - Server doesn't support this Content-Type
HTTP 415 Unsupported Media Type
What It Means
The HTTP 415 Unsupported Media Type status code indicates that the server refuses to accept the request because the payload format is not supported. The Content-Type header doesn't match what the server expects.
Common Causes
- Missing Content-Type: No Content-Type header sent
- Wrong Content-Type: Sent XML when JSON expected
- Typo in header: "application/jason" instead of "application/json"
- Missing charset: Some servers require charset=utf-8
Example
# Wrong Content-Type
POST /api/users HTTP/1.1
Content-Type: text/plain
{"name": "John"}
---
HTTP/1.1 415 Unsupported Media Type
Content-Type: application/json
{
"error": "Unsupported Media Type",
"message": "Expected application/json, got text/plain"
}
The Fix
# Correct request
POST /api/users HTTP/1.1
Content-Type: application/json
{"name": "John"}
---
HTTP/1.1 201 Created
Common Content-Types
| Type | Use For |
|---|---|
| application/json | JSON APIs |
| application/x-www-form-urlencoded | HTML form data |
| multipart/form-data | File uploads |
| application/xml | XML APIs |
Server Implementation
// Express.js - validate Content-Type
app.use((req, res, next) => {
if (['POST', 'PUT', 'PATCH'].includes(req.method)) {
const contentType = req.get('Content-Type');
if (!contentType?.includes('application/json')) {
return res.status(415).json({
error: 'Unsupported Media Type',
message: 'Content-Type must be application/json'
});
}
}
next();
});
Client Examples
fetch
fetch('/api/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ name: 'John' })
});
curl
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name": "John"}'