gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 16:49:28 24 4
gpt4 key购买 nike

如果您对资源执行 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 furtheraction needs to be taken by the user agent in order to fulfill therequest. [...]

There are several types of redirects:

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

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

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

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

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

4.1. 304 Not Modified

The 304 (Not Modified) status code indicates that a conditional GETor HEAD request has been received and would have resulted in a 200(OK) response if it were not for the fact that the conditionevaluated to false. In other words, there is no need for the serverto transfer a representation of the target resource because therequest indicates that the client, which made the requestconditional, already has a valid representation; the server istherefore redirecting the client to make use of that storedrepresentation as if it were the payload of a 200 (OK) response.

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com