【发布时间】:2016-10-27 21:41:57
【问题描述】:
所以我有这个代码
$http({
'method': 'GET',
'url': 'http://www.example.com',
'withCredentials': true,
headers: {
'Content-type': 'application/json'
}
}).
success(function (data, response, headers, status) {
});
这将返回 JSON 记录数组,并且 http 请求使用凭据,这是一个 JSESSIONID,用于对后端的每次连续调用。
问题是,它可以在 Firefox 上运行,但不能在 chrome 上运行。因此,当我已经将 withCredentials 设置为 true 时,Firefox 确实发送了包含 JSESSIONID 但不包含 chrome 的 cookie
为什么会这样?
【问题讨论】:
-
您尝试调试请求,确定“withCredentials”标头发送正确吗?
-
我如何确保这一点? @NarekMamikonyan
-
当您打开 chrome dev tools 网络部分时,您可以看到请求标头等。
-
yap 实际上这是凭据“Access-Control-Allow-Credentials:true”的响应标头,但它不像 firefox 那样发送 JSESSIONID
-
供您参考 chrome 给出此错误 'XMLHttpRequest 无法加载 example.com/orders。该请求被重定向到“example.com/auth/login”,这对于需要预检的跨域请求是不允许的。 ' @NarekMamikonyan
标签: javascript angularjs http jsessionid