第一步: 服务器必须在Response Header中设置: Access-Control-Allow-Credentials: true

第二步: 客户端发起请求时需要将 xhr.withCredentials设为: true;

var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://example.com/', true);
xhr.withCredentials = true;
xhr.send(null);

 

注意: 

1. 按照上面设置后, 不仅Cookie会被附带上, 认证的头信息也会被附带;

2. 按照上面设置后, 还可以设置远程主机指定的Cookie, 否则就算远程主机想设置, 浏览器也会忽略;

 

相关文章:

  • 2022-12-23
  • 2021-08-20
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2021-05-15
猜你喜欢
  • 2022-02-08
  • 2021-08-22
  • 2021-07-16
  • 2022-12-23
  • 2021-12-21
  • 2021-09-25
  • 2021-11-20
相关资源
相似解决方案