在跨源请求中发送 cookie

问题描述 投票:0回答:0

我在 https://xxx.googleusercontent.com/client 中有一个脚本。在这个脚本中,我发出了一个 Http 请求以从 https://backend.com/api/songs:

获取一些数据
const clicked = () => {
  fetch("http://backend.com/api/songs", 
    { headers: { crossDoman:true, withCredentials: true}})
.then(R => {
  R.json()
  .then(data => {
    console.log(data);
  })
    .catch(err => alert("json error", err));
})
.catch(err => alert(err));
}

上述请求成功完成。然而,尽管添加了显示的两个 Http 标头,但在我当前的浏览器会话中,backend.com 的 cookie 并未在上述

fetch
请求中发送。

我需要的饼干具有

Secure
SameSite: None
设置的属性。

CORS 预检到 https://backend.com/api/songs 响应以下标头:

Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Content-Type,crossdomain,withcredentials,*
Access-Control-Allow-Methods: GET,PUT,POST,DELETE
Access-Control-Allow-Origin: https://xxx.googleusercontent.com

我需要 backend.com 的 cookie 才能使我的功能正常工作。对于要在跨域请求中发送的 backend.com cookie,上面缺少什么?

是否需要适当的集管外壳?他们必须连字符吗?

cookies cors cross-domain
© www.soinside.com 2019 - 2024. All rights reserved.