请求中未接受的 Content-Type 的 HTTP 状态代码

标签 http rest mime-types http-status-codes http-request

对于某些资源,我的 RESTful 服务器只接受以 JSON 对象作为内容主体的 PUTPOST 请求,因此需要 Content-Type application/json 而不是 application/x-www-form-urlencodedmultipart/form-data 或其他任何内容。

格式错误的 JSON(或缺少格式的 JSON)返回 400,其中错误消息直接取自 JSON 解析器引发的异常,用于调试目的。

哪个 HTTP 错误代码表示客户端发送了一个 Not Acceptable Content-Type 请求,即使服务器可以在技术上解析请求内容?

最佳答案

根据此列表,它可能是 415 Unsupported Media Type:http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.16 .

第三方编辑

来自当前RFC9110 HTTP Semantics

The 415 (Unsupported Media Type) status code indicates that the origin server is refusing to service the request because the content 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.

If the problem was caused by an unsupported content coding, the Accept-Encoding response header field (Section 12.5.3) ought to be used to indicate which (if any) content codings would have been accepted in the request.

On the other hand, if the cause was an unsupported media type, the Accept response header field (Section 12.5.1) can be used to indicate which media types would have been accepted in the request.

来源RFC9110 - 415 unsupported media type

关于请求中未接受的 Content-Type 的 HTTP 状态代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11973813/

相关文章:

python-3.7 - mimetypes.guess_type 在 python3.7.3 上无法识别视频/x-m4v

Ruby Http Post 参数

c++ - 从 Poco http 客户端获取对字符串的响应

rest - 如果后端离线,则不提供静态文件

rest - 如何通过REST API获取所有mapreduce作业的状态?

java - 如何使用 Java 将 text/html 和 text/plain 复制到剪贴板

delphi - 如何使用 TIdHTTPServer 和 OpenSSL 在同一端口上支持 SSL 和非 SSL 流量?

HttpClient - 大型上传的两次超时

android - 玩! Android 客户端的 Framework 2 REST 身份验证和授权

ruby - 从文件名中获取 mimetype