Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http 301 302 307之间的区别 #154

Open
sisterAn opened this issue Mar 2, 2021 · 0 comments
Open

http 301 302 307之间的区别 #154

sisterAn opened this issue Mar 2, 2021 · 0 comments

Comments

@sisterAn
Copy link
Owner

sisterAn commented Mar 2, 2021

301/302/303/307/308的区别

301,302是http1.0的内容,303、307、308是http1.1的内容。

301和302本来在规范中是不允许重定向时改变请求方法的(将POST改为GET),但是许多浏览器却允许重定向时改变请求方法(这是一种不规范的实现)。

303的出现正是为了给上面的301,302这种行为作出个规范(将错就错吧),也就是允许重定向时改变请求方法。此外303响应禁止被缓存。

   大多数的浏览器处理302响应时的方式恰恰就是上述规范要求客户端处理303响应时应当做的,所以303基本用的很少,一般用302。

307和308的出现也是给上面的行为做个规范,不过是不允许重定向时改变请求方法

Permanent

Temporary

Allows changing the request method from POST to GET.

301302

Does not allow changing the request method from POST to GET.

308307

注:永久(Permanent)和临时(Temporary)的区别

永久是指原来访问的资源已经永久删除啦,客户端应该根据新的URI访问重定向。

临时是指访问的资源可能暂时先用location的URI访问,但旧资源还在的,下次你再来访问的时候可能就不用重定向了。

故301与302的区别:

301表示搜索引擎在抓取新内容的同时也将旧的网址交换为重定向之后的网址;302表示旧地址A的资源还在(仍然可以访问),这个重定向只是临时地从旧地址A跳转到地址B,搜索引擎会抓取新的内容而保存旧的网址。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant