跨域cookie设置

1.后端设置

 Access-Control-Allow-Credentials 设置为true

 设置:Access-Control-Allow-Origin

2.前端设置

设置:withCredentials: true

以axios为例:在request config中设置:withCredentials: true

以上参考:https://stackoverflow.com/questions/46288437/set-cookies-for-cross-origin-requests

3.设置domain的问题:.

参考:https://stackoverflow.com/questions/1134290/cookies-on-localhost-with-explicit-domain?answertab=votes#tab-top

31.如果cookies中的domain有端口信息,chrome浏览器会自动过滤掉这个cookie。

3.2.按设计,domain 必须有至少两个点,否则浏览器会认为该domain是非法的。

3.3.在localhost上,domain应该省略,设置为null、‘’,flase 不够

可以尝试不设置domain,或者是为null、‘’、false

我设置了domain为null,可以;具体原因不知。

猜你喜欢

转载自www.cnblogs.com/huozaimengli/p/11075992.html