【发布时间】:2013-09-09 16:43:54
【问题描述】:
我遇到了一个神秘问题,Chrome 在遇到 HTTP 重定向时会取消跨域 AJAX 请求。在“网络”选项卡中,它显示为“(已取消)”,并且响应标头或正文不可用。
流程如下:
- 在 http:// 上加载页面
- 在 https:// 上向登录端点发送 POST 请求
- 303 响应
- 请求已取消。
这是 JS(来自ajaxtest.html):
var r = new XMLHttpRequest();
r.open('POST', 'https://dev.example.com/appName-rest/login', true);
r.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
r.send(JSON.stringify({"username":"myusername","password":"myrealpassword"}));
r.send();
Chrome 的网络内部显示服务器使用以下标头进行响应:
HTTP/1.1 303 See Other
Date: Thu, 05 Sep 2013 17:54:21 GMT
Server: Apache/2
Access-Control-Allow-Origin: http://dev.example.com
Access-Control-Allow-Credentials: true
Location: https://dev.example.com/appName-rest/j_spring_cas_security_check?ticket=xxxx.example.com
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
Content-Length: 52
Connection: close
Content-Type: text/plain; charset=UTF-8
它说:URL_REQUEST_BLOCKED_ON_DELEGATE
有人知道为什么会失败吗?
【问题讨论】:
-
你在使用WebService吗?
-
不确定.. 我想是的。但代码只是普通的 javascript。
标签: ajax google-chrome redirect cors http-response-codes