版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Juniorselk/article/details/80942796
fetch:
前端请求的时候设置credentials: "include",同时需要后台配置允许浏览器response.setHeader("Access-Control-Allow-Credentials","true"),如果不配置可以请求成功,但是返回的数据有误。
axios:
前端请求的时候设置withCredentials:true来解决;
同样后台也需要配置,header信息Access-Control-Allow-Credentials:true,
Access-Control-Allow-Origin不可以为 '*',因为 '*' 会和 Access-Control-Allow-Credentials:true 冲突,需配置指定的地址。