![](/img/trans.png)
[英]Why isn't my CORS fetch request sending cookies to the server?
[英]Why isn't the post request sending cookies?
我正在尝试将包含我的刷新令牌的 HTTPonly cookie 发送到我的服务器。 cookie如下所示
res.cookie('refreshtoken', token, {
httpOnly: true,
sameSite: 'strict',
path: '/refresh_token',
expires: new Date(Date.now() + 7 * 216000000) // Token expires in 7 days
});
我正在向在同一端口/域上运行的服务器发出发布请求,因此它不需要 cors。 当我查看发送的请求时,没有发送 cookies。 我在 localhost 上运行我的服务器,这可能会导致问题,但我不确定。
无论我使用同源还是包含凭据,都不会发送 cookie。
const result = await (
await fetch('http://localhost:5000/api/refresh_token', {
method: 'POST',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
}
})).json();
对于将来阅读本文的任何人,路径是指绝对路径。 所以 'api/refresh_token' 不会与 '/refresh_token' 匹配。 这允许发送我的 cookie。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.