HTTP status code for unaccepted Content-Type in request
39,588
It could be 415 Unsupported Media Type
according to this list: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.16.
Related videos on Youtube
Author by
Jordan
Updated on May 07, 2020Comments
-
Jordan almost 4 years
For certain resources, my RESTful server only accepts
PUT
andPOST
requests with JSON objects as the content body, thus requiring aContent-Type
ofapplication/json
instead ofapplication/x-www-form-urlencoded
ormultipart/form-data
or anything else.Malformed JSON (or lack thereof) returns a
400
with the error message taken directly from the exception raised by the JSON parser, for debugging purposes.Which HTTP error code means that the client sent a request with an unacceptable
Content-Type
, even if the server could technically parse the request content?-
Chris Halcrow over 10 yearsSee here for a definitive answer: stackoverflow.com/questions/19417553/…
-
Frans about 2 yearsYour server couldn't technically parse the content if the
Content-Type
was incorrect: how would it know for sure how to parse it?
-
-
blackstrype over 9 yearsI'm still wondering if there a difference between "unnaccepted content type" and "unsupported media type" -- where the actual content (potentially different from the declared content) does not match with what is intended.
-
Julian Reschke almost 9 years415 is correct, but you shouldn't use RFC 2616; it has been obsoleted by RFC 7231.
-
Ashith about 8 years
415 Unsupported Media Type
means the client has provided data in a format that the server doesn't support (as indicated by the request'sContent-Type
header). For example, trying to do aPOST
request to create record of typeUser
with the resource in formatapplication/xml
but the server can't process XML requests for that resource type.406 Not Acceptable
means the incoming request is wanting the response data in a specific format (as indicated by theAccept
header) which the server can't provide (for example, wanting a record as XML when the server only provides JSON). -
user192127 almost 8 yearscareful parsing of the language of 7231 (2616 is superseded) says otherwise "The 415 (Unsupported Media Type) status code indicates that the origin server is refusing to service the request because the payload is in a format not supported by this method on the target resource. 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." - read that carefully. 415 is widely regarded (not correctly IMO) as appropriate but it is not. Convenient use is 1 thing; provable correctness is another
-
Frans about 2 yearsContent without a content type is basically meaningless. So the distinction that @blackstrype and @user192127 seem to want to make between the two doesn't exist. If you get a
Content-Type
header that indicates a media type you don't accept,415 Unsupported Media Type
is absolutely the correct response. If you get content with noContent-Type
header, then you should reject the request outright because you would have no definitive way to know how to parse the content.