https://www.rfc-editor.org/rfc/rfc7231#section-5.3.2指出
A request without any Accept header field implies that the user agent will accept any media type in response.
还有 https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html指出
If no Accept header field is present, then it is assumed that the client accepts all media types. If an Accept header field is present, and if the server cannot send a response which is acceptable according to the combined Accept field value, then the server SHOULD send a 406 (not acceptable) response.
不过,在这种情况下发回 406 Not Acceptable 是否错误? 特别是,我们希望强制客户编写版本感知的客户端代码(我们的内容类型已修改版本)。
最佳答案
would it be wrong to send back a
406
Not Acceptable in such case?
简短的回答是是,答案在您自己的问题中。一旦 RFC 2616 不再相关,请考虑 RFC 7231 中的引述:
A request without any
Accept
header field implies that the user agent will accept any media type in response.
RFC 7231 的同一段说明了在什么情况下可以使用 406
状态码:
If the header field is present in a request and none of the available representations for the response have a media type that is listed as acceptable, the origin server can either honor the header field by sending a
406
(Not Acceptable) response or disregard the header field by treating the response as if it is not subject to content negotiation.
查看406
如何状态码定义:
The
406
(Not Acceptable) status code indicates that the target resource does not have a current representation that would be acceptable to the user agent, according to the proactive negotiation header fields received in the request (Section 5.3), and the server is unwilling to supply a default representation.
关于http - 在客户端请求没有 Accept header 的情况下发送 406 是否有效 HTTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51631167/