internet-explorer - IE 在 POST -> 重定向 -> GET 场景中忽略 303 重定向

标签 internet-explorer redirect http-post post-redirect-get

我有一个启用 OAuth2 的站点,该站点遇到与 IE 如何处理 303 响应相关的问题。在流程中,发生了 3 次重定向。

### Chrome/Firefox
POST idp.com/login           (res 302 -> idp.com/authenticate)
GET  idp.com/authenticate    (res 302 -> app.com/oauth2/callback)
GET  app.com/oauth2/callback (res 303 -> app.com/home)
GET  app.com/home

### IE
POST idp.com/login           (res 302 -> idp.com/authenticate)
POST idp.com/authenticate    (res 302 -> app.com/oauth2/callback)
POST app.com/oauth2/callback (res 303 -> app.com/home)
POST app.com/home

由于某种原因,IE 似乎正在维护原始请求方法。我试图通过返回 303 来至少打破我的服务器 (app.com) 上的原始 POST 响应,但这也没有解决问题。这是出乎意料的,因为 RFC 2068 指出对于 303 - See Other回应,以下应予尊重

The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource.



我什至尝试了 307 响应,但没有成功。有没有人对这里发生的事情有任何想法?

最佳答案

在 LinkedIn OAuth 和我的应用程序中遇到了类似的问题后,我以一种特别不优雅的方式解决了这个问题。我允许我的回调地址使用 POST 方法,然后在我的 servlet 实现内部将其视为 GET 调用。

    @RequestMapping(value = ApiValues.LINKEDIN_CALLBACK, method = RequestMethod.POST)
public void doPost(HttpServletRequest request, HttpServletResponse response,
        @RequestParam(value = "oauth_token", required = false) String tokenString,
        @RequestParam(value = "oauth_verifier", required = false) String verifierString) throws ServletException, IOException {

    handleCallBack(request, response, tokenString, verifierString);
}


@RequestMapping(value = ApiValues.LINKEDIN_CALLBACK, method = RequestMethod.GET)
public void doGet(HttpServletRequest request, HttpServletResponse response,
        @RequestParam(value = "oauth_token", required = false) String tokenString,
        @RequestParam(value = "oauth_verifier", required = false) String verifierString) throws ServletException, IOException {

    handleCallBack(request, response, tokenString, verifierString);
}

注意到似乎只有 IE(和旧版本的 IE)才提供这个问题,Chrome、Firefox 和 Safari 似乎都按照规范重定向到 GET。

关于internet-explorer - IE 在 POST -> 重定向 -> GET 场景中忽略 303 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28513449/

相关文章:

javascript - 在 IE 中获取页面引用的最可靠方法是什么?

javascript - 如何使用 html 将 Windows Phone(但不是桌面 Windows)重定向到移动网站?

Android - session Cookie

c# - MVC4 忽略 [HttpGet] 和 [HttpPost] 属性

html - IE9 中的居中 Div 没有固定的高度/宽度

html - CSS 伪类不适用于主导航链接

php - 更改域、重定向并且不丢失页面排名

java - 如何使 Spring Integration HTTP outbound-channel-adapter 参与 Global Transaction

flash - wmode=transparent 对于 Youtube 视频 Iframe 无法在具有 Bootstrap 模式的 IE 中工作

PHP curl() 一次获取所有标题