如果我设置了X-XSRF-TOKEN cookie服务器端,我需要设置什么来发送XSRF-TOKEN标头吗?
https://github.com/axios/axios/blob/master/lib/defaults.js#L74 https://github.com/axios/axios/blob/master/dist/axios.js#L1072
看起来我不想,但我没看到有一辆出去了。
我要补充的是,我已经将withCredentials设置为true,所以我确实满足OR中的第一个检查:
var xsrfValue = (config.withCredentials || isURLSameOrigin(config.url)) && config.xsrfCookieName ?
cookies.read(config.xsrfCookieName) :
undefined;
if (xsrfValue) {
requestHeaders[config.xsrfHeaderName] = xsrfValue;
}因此,如果config.xsrfCookieName是缺省的.....
更新:
因此,我的OPTIONS印前检查CORS正在工作,POST现在也是如此,但没有发送X-XSRF-TOKEN。
methods: {
onSubmit(e) {
this.axios
.post(
e.target.action,
{ data: this.form },
{
withCredentials: true,
xsrfCookieName: "XSRF-TOKEN",
xsrfHeaderName: "X-XSRF-TOKEN"
}
)
.then(res => {
console.log(res)
})
.catch(err => {
this.errors.push(err)
})
}
}谢谢。
发布于 2019-01-10 23:36:43
我遇到了同样的问题,并且是关于cookie上的"secure“标志,可以在请求的cookies选项卡上看到,但不会显示在"application”选项卡下的cookie上:

在我的例子中,我不得不让后端把它写下来。这是因为,出于安全考虑,您不能通过javascript访问它。
document.cookie // is emptyhttps://stackoverflow.com/questions/52863990
复制相似问题