chrome浏览器跨域请求cookie丢失问题

1,051 阅读1分钟
问题:
在前后端都设置了相关配置之后,在浏览器中请求header中依旧没有cookie!!!
在响应头中有set-cookie字段,但是请求头中缺少了cookie字段,
情况如下:
(ps:axios请求中需要配置withCredentials: true;Vue在发起跨域请求时,后端已经开启CORS,前端需要也携带cookie,此时需要在前端请求头加上**withCredentials: true**,表示请求可以携带cookie)

image.png

解决方法:
1、打开chrome,输入chrome://flags/ ,搜索 SameSite by default cookies;
2、找到SameSite by default cookies和Cookies without SameSite must be secure将上面两项设置为 Disable,最后底部relaunch 重新加载下即可!!

image.png

再次打开时,已经有cookie了

image.png