如果您对资源执行 GET
请求,那么您可以获得 Not Modified 响应以避免不必要的流量是非常有意义的。
问题是为什么返回码是304
?这意味着它是一个重定向 响应。在这种情况下,预期的重定向位置是什么?
我原以为它是 2xx
范围内的东西,因为它是一个成功请求和一个有效的答案。
参见 RFC .
最佳答案
请不要再使用过时的旧 RFC 2616 作为引用。它已被 RFC 7230-35 完全废弃,它们一起定义了 HTTP 协议(protocol)。
如 RFC 7231 中所述,有几种类型的重定向,其中一种是到缓存资源的隐式重定向,如 304
所示状态代码(突出显示是我的):
The
3xx
(Redirection) class of status code indicates that further action needs to be taken by the user agent in order to fulfill the request. [...]There are several types of redirects:
Redirects that indicate the resource might be available at a different URI, as provided by the
Location
field, as in the status codes301
(Moved Permanently),302
(Found), and307
(Temporary Redirect).Redirection that offers a choice of matching resources, each capable of representing the original request target, as in the
300
(Multiple Choices) status code.Redirection to a different resource, identified by the
Location
field, that can represent an indirect response to the request, as in the303
(See Other) status code.Redirection to a previously cached result, as in the
304
(Not Modified) status code.
The
304
(Not Modified) status code indicates that a conditionalGET
orHEAD
request has been received and would have resulted in a200
(OK) response if it were not for the fact that the condition evaluated to false. In other words, there is no need for the server to transfer a representation of the target resource because the request indicates that the client, which made the request conditional, already has a valid representation; the server is therefore redirecting the client to make use of that stored representation as if it were the payload of a200
(OK) response.
关于http - 为什么 "Not Modified"是重定向 ("3xx") 状态码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51763977/