415
HTTPERRORNotable4xx Client ErrorHIGH confidence

Unsupported Media Type

Production Risk

Low. This is a very specific error that clearly tells the client developer what needs to be fixed: the format of the data being sent.

What this means

The server is refusing 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.

Why it happens
  1. 1A client sends XML to an API endpoint that only accepts JSON.
  2. 2A client sends a request with 'Content-Type: text/plain' when the server expects 'application/json'.
  3. 3An upload form sends a file with a media type the server is not configured to handle.
How to reproduce

An API client attempts to send a new user's data as a URL-encoded form string, but the server is configured to only accept JSON.

trigger — this will error
trigger — this will error
POST /api/users HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded

name=John&email=john@example.com

expected output

HTTP/1.1 415 Unsupported Media Type

Fix 1

Set the Correct Content-Type Header

WHEN Sending a request with a body.

Set the Correct Content-Type Header
// Client must send the correct header and matching body format
Content-Type: application/json

Why this works

Client-Side Correction

Fix 2

Add Support for the Media Type

WHEN You control the server and want to support the client's format.

Add Support for the Media Type
// Example in Express.js
// Add middleware to parse the new format
app.use(express.urlencoded({ extended: true }));

Why this works

Server-Side Logic

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All HTTP errors