但是未在请求标头中设置cookie值,所有其他api均失败,并出现身份验证问题,因为标头中不存在cookie值(会话ID)
带有身份验证的set-cookie的示例响应标头
HTTP/1.1 200 OK
X-Powered-By: Express
set-cookie: JSESSIONID=C6A3DE7E13C60F33D777875DB610EED2; Path=/a; HttpOnly
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
cache-control: no-cache, no-store, max-age=0, must-revalidate
pragma: no-cache
expires: 0
x-frame-options: DENY
content-type: application/json;charset=UTF-8
transfer-encoding: chunked
date: Tue, 12 May 2020 15:20:17 GMT
connection: close
以下是我在vue.config.js中的代理配置
devServer: {
proxy: {
"/": {
target: "http://localhost:8080/abc",
secure: false,
onProxyReq: function(request) {
request.setHeader("origin", "http://localhost:8080/abc");
}
}
},
disableHostCheck: true
}
这是我的axios实例创建,带有“ withCredentials:true”
withCredentials: true,
baseURL: "/",
headers: { "Content-Type": "application/json" }
});
下面是我在服务器端的网络安全配置
httpSecurity
.csrf().disable()
.httpBasic().disable()
.authorizeRequests()
.antMatchers("/auth/login").permitAll()
.antMatchers("/auth/reset-password").authenticated()
.anyRequest().authenticated();
}
注意:这在邮递员中有效,因为邮递员会自动将cookie添加到请求标头中
答案 0 :(得分:-1)
这看起来像是axios的已知问题。尝试像这样设置默认值
axios.defaults.withCredentials = true
https://github.com/axios/axios/issues/587#issuecomment-275890961