415 Unsupported Media Type
The server refuses to accept the request because the payload format is in an unsupported format.
Meaning & Description
Common Causes
- Forgetting to set the `Content-Type: application/json` header in a fetch() or curl request.
- Uploading unapproved file types (e.g., an `.exe` file to a profile picture upload route).
- A mismatch between the data serialization the client used and what the server expects.
How to fix a 415 error
- Inspect the `Content-Type` header sent by your HTTP client.
- If sending JSON data, ensure the header is strictly `Content-Type: application/json`.
- Check the API documentation to see what media types are accepted for the specific endpoint.
- If uploading a file, verify that the MIME type of the file is in the server's allowed list.
Browser & SEO Behaviour
Browser Behavior
Browsers automatically set the `Content-Type` for form submissions (e.g., `application/x-www-form-urlencoded` or `multipart/form-data`), but custom Fetch/XHR requests need manual header configuration.
SEO Impact
No direct SEO impact, as search bots primarily issue GET requests without payloads.
CDN Behavior
CDNs generally pass the payload and headers to the origin without evaluating the `Content-Type` against the body, leaving the 415 generation to the origin server.
Code Examples
HTTP/1.1 415 Unsupported Media Type
Content-Type: application/json
{
"error": "Only application/json is accepted."
}app.post("/api/data", (req, res) => {
if (!req.is("application/json")) {
return res.status(415).send("Unsupported Media Type: expected application/json");
}
// Proceed with JSON processing
});from fastapi import FastAPI, Request, HTTPException
app = FastAPI()
@app.post("/upload")
async def upload_file(request: Request):
content_type = request.headers.get("content-type", "")
if not content_type.startswith("image/jpeg"):
raise HTTPException(status_code=415, detail="Only JPEG images are supported")
return {"message": "Success"}func handler(w http.ResponseWriter, r *http.Request) {
contentType := r.Header.Get("Content-Type")
if contentType != "application/json" {
http.Error(w, "Unsupported Media Type", http.StatusUnsupportedMediaType)
return
}
w.WriteHeader(http.StatusOK)
}[HttpPost]
[Consumes("application/json")]
public IActionResult PostData([FromBody] MyModel data)
{
// ASP.NET Core automatically returns 415 if the Content-Type is not application/json
return Ok();
}# Missing Content-Type header when sending JSON will often trigger 415
curl -X POST https://api.example.com/data -d '{"name": "test"}'Raw HTTP Response Example
HTTP/1.1 415 Unsupported Media Type
Date: Wed, 21 Oct 2026 07:28:00 GMT
Content-Type: application/json
{"error": "Unsupported format. Use application/json"}Real-world Examples
Frequently Asked Questions
What is the difference between 415 Unsupported Media Type and 406 Not Acceptable?
415 means the client sent data in a format the server doesn't understand (checked via `Content-Type`). 406 means the server can't return data in the format the client requested (checked via the `Accept` header).
Why does my fetch() request return a 415 error?
By default, fetch() may send data as `text/plain` if a `Content-Type` header isn't explicitly set. If your API expects JSON, you must manually add `headers: { "Content-Type": "application/json" }`.
Should I return a 415 or 400 when JSON is malformed?
If the `Content-Type` is correctly set to `application/json` but the JSON syntax is broken, return a 400 Bad Request. If the `Content-Type` is wrong entirely, return a 415.
Did You Know?
The 415 status code relies on the client accurately reporting what it is sending. Malicious clients might lie and send executable code labeled as an image, which is why servers must also do content inspection, not just header checking.
Developer Tips
- Modern web frameworks (like ASP.NET Core or Spring Boot) often handle 415 validation automatically if you explicitly define what content types your routes consume.
- When returning a 415, always include a helpful message in the response body stating exactly which media types *are* supported.
Interview Questions
These are questions you might face in a backend or API design interview that touch on HTTP 415.
Explain the difference between `Content-Type` and `Accept` headers in the context of HTTP status codes.
`Content-Type` tells the server the format of the data being *sent* by the client; if wrong, the server returns 415 Unsupported Media Type. `Accept` tells the server what format the client *wants* back; if the server cannot produce it, it returns 406 Not Acceptable.
Common Interview Mistakes
- Confusing 415 with 406. Remember: 415 is about the Request (Content-Type), 406 is about the Response (Accept).
- Saying 415 should be returned when JSON parsing fails due to syntax errors (that should be a 400).