http - 为什么 "Not Modified"是重定向 ("3xx") 状态码?

标签 http http-status-codes

如果您对资源执行 GET 请求,那么您可以获得 Not Modified 响应以避免不必要的流量是非常有意义的。

问题是为什么返回码是304?这意味着它是一个重定向 响应。在这种情况下,预期的重定向位置是什么?

我原以为它是 2xx 范围内的东西,因为它是一个成功请求和一个有效的答案。

参见 RFC .

最佳答案

请不要再使用过时的旧 RFC 2616 作为引用。它已被 RFC 7230-35 完全废弃,它们一起定义了 HTTP 协议(protocol)。


RFC 7231 中所述,有几种类型的重定向,其中一种是到缓存资源的隐式重定向,如 304 所示状态代码(突出显示是我的):

6.4. Redirection 3xx

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:

  1. Redirects that indicate the resource might be available at a different URI, as provided by the Location field, as in the status codes 301 (Moved Permanently), 302 (Found), and 307 (Temporary Redirect).

  2. Redirection that offers a choice of matching resources, each capable of representing the original request target, as in the 300 (Multiple Choices) status code.

  3. Redirection to a different resource, identified by the Location field, that can represent an indirect response to the request, as in the 303 (See Other) status code.

  4. Redirection to a previously cached result, as in the 304 (Not Modified) status code.

请参阅下面的 304状态代码在 RFC 7232 中定义:

4.1. 304 Not Modified

The 304 (Not Modified) status code indicates that a conditional GET or HEAD request has been received and would have resulted in a 200 (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 a 200 (OK) response.

关于http - 为什么 "Not Modified"是重定向 ("3xx") 状态码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51763977/

相关文章:

java - ReSTLet 路由器相对路径错误

php - 如何将 PHP 脚本变成代理服务器?

"No Content"消息的 HTTP 状态代码

http - 进程未运行的最佳 HTTP 错误代码?

C# HttpClient 文件流内容边界头错误

java - 使用 HttpClient 在 Java 中进行 Http 基本身份验证?

http - 如何让 netcat 通过多个 TCP 段发送 HTTP header ?

node.js - express .JS : how can I set response status by name rather than number?

redirect - 非SEO反欺骗外部链接重定向: Status code?

http - 为错误的协议(protocol)返回什么 HTTP 代码