HTTP 415 Unsupported Media Type — What It Means and How to Fix It
The HTTP 415 (Unsupported Media Type) status code indicates that the server refuses to accept the request because the payload format is in an unsupported format. This typically occurs when the client sends data with a `Content-Type` header that the server does not understand or is not configured to process for the requested resource.
Essential Reading: Designing Data-Intensive Applications
The system design bible for software engineers. Learn to build reliable, scalable, and maintainable systems.
Common Causes
- Incorrect `Content-Type` header in the request (e.g., sending JSON with `Content-Type: text/plain`).
- Missing `Content-Type` header when one is expected by the server.
- The server's API or endpoint only accepts specific media types, and the client sent a different one.
- The server is configured to reject certain media types for security or processing reasons.
Code Examples to Handle HTTP 415
curl -I https://httpbin.org/status/415
How to Fix It
- **Client-side:** Verify the `Content-Type` header in your request. Ensure it accurately reflects the format of the data being sent (e.g., `application/json`, `application/xml`, `multipart/form-data`).
- **Client-side:** Consult the API documentation for the specific endpoint you are calling to determine the expected media types. Adjust your request accordingly.
- **Server-side:** Check the server-side code or configuration for the endpoint. Ensure it is set up to correctly parse and accept the `Content-Type` you are sending. This might involve adding parsers or updating middleware.
- **Server-side:** If using a framework, review its body parser configurations. For example, in Node.js with Express, ensure `express.json()` or `express.urlencoded()` are correctly applied if expecting JSON or URL-encoded data.
Related Status Codes
Frequently Asked Questions
What causes HTTP 415?
HTTP 415 is caused when the server receives a request with a payload in a format it doesn't support or isn't configured to process, as indicated by the `Content-Type` header.
How do I fix HTTP 415?
To fix HTTP 415, ensure the `Content-Type` header in your request accurately reflects the data format you're sending (e.g., `application/json` for JSON). If you're the server owner, verify your server-side code or configuration supports the expected media types.