415 Unsupported Media Type
HTTP response status code 415 Unsupported Media Type is a client error that is returned by the server to indicate that the content of a message body is not supported.
Usage
When the 415 Unsupported Media Type error message is received, it may be as a result of the Content-Type or Content-Encoding headers being rejected by the server. Alternatively, the server may return this error based upon further inspection of the message body.
In the latter case, the server may indicate this error because it has trouble parsing or otherwise deciphering or recognizing the content. In cases where the server recognizes the media but it is not supported, the 415 Unsupported Media Type status is most accurate. However, if the content cannot be parsed and may contain an error then HTTP response 400 Bad Request or 422 Unprocessable Entity may be more appropriate.
This error is similar to 406 Not Acceptable, except that it is based on the Content-Type and Content-Encoding headers, rather than on the Accept header.
Note
Search engines like Google will not index a URL with 415 Unsupported Media Type response status, and consequently, URLs that have been indexed in the past but are now returning this HTTP status code will be removed from the search results.
Example
In the example, the client wants to send a message in plain text, but the server sends the 415 Unsupported Media Type error because it only accepts HTML messages. The client subsequently changes the Content-Type header but leaves the original message intact. The server can recognize that it is not a valid HTML structure and consequently, denies the request a second time.
Initial request
POST /blog/newmessage HTTP/1.1
Host: www.example.re
Content-Type: text/plain
Content-Length: 24
Good morning, Everybody!
Initial response, based on examining the Content-Type header
HTTP/1.1 415 Unsupported Media Type
Content-Type: text/html
Content-Length: 138
<html>
<head>
<title>Unsupported Format</title>
</head>
<body>
<p>Please use HTML to post new messages.</p>
</body>
</html>
Subsequent request to attempt to fool server
POST /blog/newmessage HTTP/1.1
Host: www.example.re
Content-Type: text/html
Content-Length: 24
Good morning, Everybody!
Subsequent response, based on examining the message body
HTTP/1.1 415 Unsupported Media Type
Content-Type: text/html
Content-Length: 174
<html>
<head>
<title>Unsupported Format</title>
</head>
<body>
<p>No HTML tags were found. Please ensure you use HTML to post new messages.</p>
</body>
</html>
Code references
.NET
HttpStatusCode.UnsupportedMediaType
Rust
http::StatusCode::UNSUPPORTED_MEDIA_TYPE
Rails
:unsupported_media_type
Go
http.StatusUnsupportedMediaType
Symfony
Response::HTTP_UNSUPPORTED_MEDIA_TYPE
Python3.5+
http.HTTPStatus.UNSUPPORTED_MEDIA_TYPE
Java
java.net.HttpURLConnection.HTTP_UNSUPPORTED_TYPE
Apache HttpComponents Core
org.apache.hc.core5.http.HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE
Angular
@angular/common/http/HttpStatusCode.UnsupportedMediaType
Takeaway
The 415 Unsupported Media Type status code is a client error that occurs when the client sends, or attempts to send, a message body to the server that contains an unsupported media type. It may be denied based on the Content-Type or Content-Encoding headers, or after inspection of the message body.