【发布时间】:2019-11-14 08:26:57
【问题描述】:
我有一个使用 GET 请求提供文件的域(比如 cookiebaker.com)。每当发出请求时,cookiebaker 服务器都会在文件响应中添加一个 set-cookie 标头。
这是一个示例标题(Max-Age 设置为未来 1 个月):
set-cookie: cookie_name=cookie_value; Max-Age=2592000; secure; HttpOnly; SameSite=Lax
现在,当我从不同的域(例如 munchies.com)调用 cookiebaker.com 时,我可以在 GET 响应中看到 set-cookie 标头,但 munchies.com 不存储 cookie。开发工具中没有看到cookie,后续请求中也没有上传。
我知道在执行 GET 请求时我必须将“withCredentials”标志设置为 true,但这对我的情况没有帮助。
这是我精简的 munchies.com 代码:
let request = new XMLHttpRequest();
request.open('GET', "https://cookieBaker.com?param=value");
request.withCredentials = true; // Tell the browser to receive cookies
request.send();
还有什么可以阻止 cookie 存储在浏览器中的吗?这些是 GET 响应中包含的所有访问控制标头(localhost 是我测试的 munchies.com 的“真实”名称):
access-control-allow-credentials: true
access-control-allow-headers: Authorization, Content-Type
access-control-allow-methods: OPTIONS, GET, POST, PUT, PATCH, DELETE
access-control-allow-origin: http://localhost
access-control-expose-headers: X-WP-Total, X-WP-TotalPages
【问题讨论】:
标签: cookies httpcookie