Logo
DevUtilsAll-in-one toolkit
Back to all codes
4154xx
4xx — Client Error

Unsupported Media Type

The media format of the requested data is not supported by the server.

What it means

The HTTP 415 Unsupported Media Type client error response code indicates that the server refuses to accept the request because the payload format is in an unsupported format.

The format problem might be due to the request's indicated `Content-Type` or `Content-Encoding`, or as a result of inspecting the data directly.

How it works

  • 1The client sends a POST request with `Content-Type: text/plain`.
  • 2The API endpoint strictly expects `application/json`.
  • 3The server rejects the payload with 415 before even trying to parse it.

Why you're seeing this

  • The client forgot to set the `Content-Type` header.
  • The client sent the wrong format.

How to fix it

  • Ensure your fetch/axios request includes `headers: { 'Content-Type': 'application/json' }`.

Framework Implementations

Express.js

app.post('/api/data', (req, res, next) => {
  if (req.headers['content-type'] !== 'application/json') {
    return res.status(415).send('Unsupported Media Type');
  }
  next();
});

Real-Life Scenarios

Use this to validate the incoming `Content-Type` header on your API routes. Rejecting bad types early prevents parsing errors and security vulnerabilities.

Image Upload Formats

An API expects a PNG or JPEG upload (`image/png`). The user tries to upload an SVG (`image/svg+xml`). The server returns 415.

HTTP Transaction

1. Client Request

POST /api/users HTTP/1.1
Content-Type: text/plain

{"name": "John"}

2. Server Response

HTTP/1.1 415 Unsupported Media Type
Content-Type: application/json

{"error": "Only application/json is supported"}

SEO Implications

None.

Related Codes