gpt4 book ai didi

http - HTTP 301 和 308 状态代码有什么区别?

转载 作者:行者123 更新时间:2023-12-02 11:37:38 28 4
gpt4 key购买 nike

HTTP 301308 状态代码有什么区别?

  • 301(永久移动):此请求和所有 future 的请求应定向到给定的 URI。

  • 308(永久重定向):应使用另一个 URI 重复该请求和所有 future 的请求。

它们看起来很相似。

最佳答案

301302307 概述

RFC 7231是 HTTP/1.1 协议(protocol)语义和内容的当前引用,定义了 301 (永久移动)和302 (找到)状态代码,允许将请求方法从 POST 更改为 GET。该规范还定义了307 (临时重定向)状态代码,不允许将请求方法从 POST 更改为 GET

查看下面的更多详细信息:

6.4.2. 301 Moved Permanently

The 301 (Moved Permanently) status code indicates that the targetresource has been assigned a new permanent URI and any futurereferences to this resource ought to use one of the enclosed URIs. [...]

Note: For historical reasons, a user agent MAY change the requestmethod from POST to GET for the subsequent request. If thisbehavior is undesired, the 307 (Temporary Redirect) status codecan be used instead.

6.4.3. 302 Found

The 302 (Found) status code indicates that the target resourceresides temporarily under a different URI. Since the redirectionmight be altered on occasion, the client ought to continue to use theeffective request URI for future requests. [...]

Note: For historical reasons, a user agent MAY change the requestmethod from POST to GET for the subsequent request. If thisbehavior is undesired, the 307 (Temporary Redirect) status codecan be used instead.

6.4.7. 307 Temporary Redirect

The 307 (Temporary Redirect) status code indicates that the targetresource resides temporarily under a different URI and the user agentMUST NOT change the request method if it performs an automaticredirection to that URI. Since the redirection can change over time,the client ought to continue using the original effective request URIfor future requests. [...]

Note: This status code is similar to 302 (Found), except that itdoes not allow changing the request method from POST to GET. Thisspecification defines no equivalent counterpart for 301 (MovedPermanently) (RFC 7238, however, defines the status code 308(Permanent Redirect) for this purpose).

将请求方法从 POST 更改为 GET

用户代理可能将请求从 POST 更改为 GET 的“历史原因”在 Eric Lawrence 中进行了解释。的post from the IEInternals blog ,日期为 2011 年 8 月 19 日。

该帖子引用了过时的 RFC 1945 中状态代码 301 的定义。 ,于 1996 年 5 月发布,定义了 HTTP/1.0。该引文的关键部分是:

Note: When automatically redirecting a POST request after receiving a 301 status code, some existing user agents will erroneously change it into a GET request.

然后作者继续:

[...] those “user agents” referred to in this remark included the popular browsers of the day, including Netscape Navigator and Internet Explorer. Arguably, this behavior is exactly what most websites wanted — after a successful POST, send the user to a different URL to show them something else. However, the POST-converted-to-GET behavior isn’t what the authors of HTTP had intended.

需要308

RFC 7238已创建来定义 308 (永久重定向)状态代码,类似于 301 (永久移动)但不允许将请求方法从 POST 更改为 GET

308状态代码现在由 RFC 7538 定义(这废弃了 RFC 7238 )。

3. 308 Permanent Redirect

The 308 (Permanent Redirect) status code indicates that the targetresource has been assigned a new permanent URI and any futurereferences to this resource ought to use one of the enclosed URIs.Clients with link editing capabilities ought to automatically re-linkreferences to the effective request URI toone or more of the new references sent by the server, where possible. [...]

Note: This status code is similar to 301 (Moved Permanently),except that it does not allow changing the request method fromPOST to GET.

所以我们有以下内容:

                                                             +-----------+-----------+
| Permanent | Temporary |
+------------------------------------------------------------+-----------+-----------+
| Allows changing the request method from POST to GET | 301 | 302 |
+------------------------------------------------------------+-----------+-----------+
| Doesn't allow changing the request method from POST to GET | 308 | 307 |
+------------------------------------------------------------+-----------+-----------+

选择最合适的状态代码

Michael Kropat放在一起set of decision charts这有助于确定每种情况的最佳状态代码。请参阅以下内容了解 2xx3xx 状态代码:

Picking a 2xx or 3xx status code

关于http - HTTP 301 和 308 状态代码有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42136829/

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