是否存在适用于不可处理的Content-Type的正确HTTP状态代码? [英] Is there a proper HTTP status code for unprocessable Content-Type?

查看:189
本文介绍了是否存在适用于不可处理的Content-Type的正确HTTP状态代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您的Web服务器无法处理传入请求时,返回的最正确/有意义的HTTP状态代码是什么,因为它不了解传入的 Content-Type 是什么请求正文是?

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?

根据维基百科的说法,直接返回400似乎是一个坏主意:

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

我们实际上返回400解析一些内容类型的错误或类似的东西,如 application / json 或某些XML变种。

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.

所以是否有HTTP状态代码表明除了HTTP 400之外我们不知道如何处理请求?

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

推荐答案

HTTP 415不支持的媒体类型是您正在查找的状态代码f或者。

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


请求实体具有服务器或资源不支持的媒体类型。例如,客户端将图像上传为image / svg + xml,但服务器要求图像使用不同的格式。

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.

来自 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.

这篇关于是否存在适用于不可处理的Content-Type的正确HTTP状态代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆