1.引言
作者在进行联系session分布式登录的时候,遇到了一个问题,就是明明我的后端进行配置了允许跨域,但是前端依然请求失败,无法收到请求,并报出如下错误。
The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute
2.问题引入
2.1前端的axios的配置
由于需要进行使用cookie等请求凭证相关的东西,在默认情况下,axios进行发送请求到后端的时候是不提供请求凭证的(cookie、HTTP认证及客户端SSL证明等),所以需要进行设置axios.defaults.withCredentials = true
2.2后端配置跨域
由于后端是为了保证安全的,前端配置跨域可能是一种曲线救国的