【发布时间】:2019-11-06 02:22:20
【问题描述】:
我已经尝试了所有方法,但无法让 Axios 与 SAP Odata Post 服务一起使用。问题是 CSRF 令牌验证失败,但在 Postman 中工作正常。
我的请求如下所示:
const postNewTasks = async (body, headers) => (await axios.get(getHeadersandCFRSURL, {
headers: { 'authorization': auth, 'x-csrf-token': 'fetch' },
withCredentials: true
}).then((response) => {
axios({
method: 'POST',
url: postBatchOperationsURL,
headers: {
"Authorization": auth,
"Content-Type": "multipart/mixed; boundary=batch_1",
"X-CSRF-Token": response.headers["x-csrf-token"], // set CSRF Token for post or update
},
withCredentials: true,
body: body
}).then(function (response) {
console.log(response)
return response
}).catch(function (err) {
console.log(err)
return err
})
})
)
有人知道为什么这个 axios 请求导致 CSRF 令牌验证失败?
【问题讨论】: