如何告诉 axios 在 post 请求中排除 cookie
how to tell axios to exclude cookie in post request
我试图覆盖 Cookie 并设置 withCredentials:false,但没有成功:
const request = await axios({
url: '/api/payments',
method: "post",
data: payload,
headers: {
"Content-Type": "multipart/form-data",
"Cookie": "access_token=''",
},
// auth token as httponly cookie
withCredentials: false,
})
Axios 只是浏览器 XMLHttpRequest
功能的包装器,它会自动处理 cookie,因此无法覆盖该行为。
就 withCredentials
标志而言,这仅适用于跨源请求的上下文。可以在这里阅读更多内容 -
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials
我试图覆盖 Cookie 并设置 withCredentials:false,但没有成功:
const request = await axios({
url: '/api/payments',
method: "post",
data: payload,
headers: {
"Content-Type": "multipart/form-data",
"Cookie": "access_token=''",
},
// auth token as httponly cookie
withCredentials: false,
})
Axios 只是浏览器 XMLHttpRequest
功能的包装器,它会自动处理 cookie,因此无法覆盖该行为。
就 withCredentials
标志而言,这仅适用于跨源请求的上下文。可以在这里阅读更多内容 -
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials