开发者社区> 问答> 正文

Ajax跨域请求如何附带Cookie

被请求端返回头已设置

Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Origin, Accept-Language, Accept-Encoding,
X-Forwarded-For, Connection, Accept, User-Agent, Host, Referer,
Cookie, Content-Type, Cache-Control, *
Access-Control-Allow-Origin:根据Referer
javascript 代码如下

var x=new XMLHttpRequest();
x.open('GET','http://reiove.duoshuo.com/api/sites/listVisitors.json',1);
x.onload=function(){
    console.log(x.responseText);
};
x.send();

但这样请求过去header里并没有附带 reiove.duoshuo.com 的 Cookie

如何让发送请求时附带所请求url站点的Cookie?

展开
收起
小旋风柴进 2016-03-24 11:23:37 2421 0
1 条回答
写回答
取消 提交回答
  • 需要本地带上x.withCredentials = true;
    在远端带上Access-Control-Allow-Credentials: true(你已经带了)

    2019-07-17 19:12:25
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
WEB浏览器中即将发生的安全变化 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载