Is there a proper HTTP status code for unprocessab

2019-08-11 09:30发布

问题:

What is the most correct/meaningful HTTP status code to return when your web server cannot handles the incoming request because it does not understands what the Content-Type of the incoming request body is?

Returning straight 400 seems like a bad idea since, according to Wikipedia:

e.g., malformed request syntax, invalid request message framing, or deceptive request routing

And we actually returns 400 when there are parsing errors or similar things for some content types like application/json or some of the XML variants.

So is there an HTTP status code to indicate that we don't know how to process the request besides HTTP 400?

回答1:

HTTP 415 Unsupported Media Type is the status code you're looking for.

The request entity has a media type which the server or resource does not support. For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format.

From the RFC:

The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.



标签: http status