开机自检后,我应该执行302重定向还是303重定向? [英] After a POST, should I do a 302 or a 303 redirect?

查看:169
本文介绍了开机自检后,我应该执行302重定向还是303重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Web应用程序的常见情况是在修改数据库的POST之后进行重定向.就像在用户创建数据库对象后将其重定向到新创建的数据库对象一样.

A common scenario for a web app is to redirect after a POST that modifies the database. Like redirecting to the newly created database object after the user creates it.

似乎大多数Web应用程序都使用302重定向,但是如果您希望使用GET来获取重定向中指定的网址,那么按照规范执行303似乎是正确的选择.从技术上讲,使用302时,浏览器应该使用与原始URL相同的方法来获取指定的URL,即POST.大多数浏览器都不会这样做.

It seems like most web apps use 302 redirects, but 303 seems to be the correct thing to do according to the specification if you want the url specified in the redirect to be fetched with GET. Technically, with a 302, the browser is supposed to fetch the specified url with the same method that the original url was fetched with, which would be POST. Most browsers don't do that though.

302- http://www.w3.org/协议/rfc2616/rfc2616-sec10.html#sec10.3.3

303- http://www.w3.org/协议/rfc2616/rfc2616-sec10.html#sec10.3.4

那么我应该使用302还是303?

So should I be using 302 or 303?

推荐答案

取决于.
HTTP1.1中添加了303和307响应.
因此,严格符合HTTP1.1 RFC的客户端代理应具有303响应.
但是可能存在一些不完全兼容或不符合HTTP1.0且不能处理303的代理.
因此,请确保大多数客户端实现都能妥善处理您的应用程序响应,我认为302是最安全的选择.
摘录自 RFC-2616 :

Depends.
303 and 307 responses were added in HTTP1.1.
So client agents that are strictly compliant to HTTP1.1 RFC should be fine with a 303 response.
But there can be agents that are not fully conformant or are HTTP1.0 compliant and will not be able to handle the 303.
So to be sure that the response of your application can be handled gracefully by the majority of client implementations I think 302 is the safest option.
Excerpt from RFC-2616:

注意:许多HTTP/1.1之前的用户代理 不懂303 状态.当需要考虑与此类客户端的互操作性时, 因为大多数用户代理都会做出反应,所以可以改用302状态代码 响应302响应,如此处针对303所述.

Note: Many pre-HTTP/1.1 user agents do not understand the 303 status. When interoperability with such clients is a concern, the 302 status code may be used instead, since most user agents react to a 302 response as described here for 303.

这篇关于开机自检后,我应该执行302重定向还是303重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆