对于某些资源,我的 RESTful 服务器只接受以 JSON 对象作为内容主体的 PUT
和 POST
请求,因此需要 Content-Type
application/json
而不是 application/x-www-form-urlencoded
或 multipart/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 .
第三方编辑
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.
关于请求中未接受的 Content-Type 的 HTTP 状态代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11973813/