但是,在请求头中没有设置cookie值,其他所有的api都会因为cookie值(session id)不在头中而导致验证失败。
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();
}
注这在postman中是可行的,因为postman会在请求头中自动添加cookie。
这看起来像是axios的一个已知问题。试试设置默认值,像这样
axios.defaults.withCredentials = true
https:/github.comaxiosaxiosissues587#issuecomment-275890961。