java 携带session 前台传递cookie 跨域解决方案 vue + java

前台 axios

设置 withCredentials: true

后台设置 跨域

header("Access-Control-Allow-Origin","源地址";
header("Access-Control-Allow-Credentials", "true");

这里 源地址 不能是*,可以设置成 谁请求你,你就设置成他的地址

后台注意 option请求

处理好option请求,不要报错

session 原理

就是发送的时候 hearder里面携带 Cookie 然后 后台session就有了。但是发现还没有,就是浏览器设置还要开启。

chrome 浏览器问题

问题是我这个chrome 没有这个值
原来我的chrome版本已经100多了,没有这个属性了,只能快捷方式加了
快捷方式后面 加 --disable-features=SameSiteByDefaultCookies
原来94版本以上 这个url的方式也不能用了,只能用Nginx方式了,但是那个方式报错 不报细节。郁闷。

换浏览器

同事有个双核浏览器 Chromium86内核 / 兼容IE内核
http://b.cqttech.com/index?p=help&ctx=settings

就有这个设置 就用这个浏览器开发就行了

chrome://flags/#same-site-by-default-cookies
chrome://flags/#enable-removing-all-third-party-cookies
用双核浏览器 改这俩

附录

Chrome处理跨域请求设置
http://t.zoukankan.com/jackielyj-p-15179862.html

关于 axios.defaults.withCredentials = true 不生效问题
https://blog.csdn.net/qq_34768777/article/details/117649075

axios请求头设置常见Content-Type和对应参数的处理
https://blog.csdn.net/weixin_42349568/article/details/123776314

chrome浏览器91版本SameSite by default cookies被移除后的解决方案,Chrome中跨域POST请求无法携带Cookie的解决方案
https://blog.csdn.net/weixin_46146313/article/details/117707199

posted @ 2022-08-17 15:38  彭成刚  阅读(440)  评论(0编辑  收藏  举报