【问题标题】:how to tell axios to exclude cookie in post request如何告诉 axios 在 post 请求中排除 cookie
【发布时间】:2022-01-02 07:06:40
【问题描述】:

我尝试覆盖 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,
  })

【问题讨论】:

    标签: javascript cookies axios http-headers http-post


    【解决方案1】:

    Axios 只是浏览器 XMLHttpRequest 功能的包装器,它自动处理 cookie,因此无法覆盖该行为。

    withCredentials 标志而言,这仅适用于跨源请求的上下文。可以在这里阅读更多内容-

    https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials

    【讨论】:

      猜你喜欢
      • 2020-12-28
      • 2020-11-07
      • 2021-12-26
      • 2015-10-23
      • 2022-12-17
      • 2017-12-08
      • 2020-04-02
      • 2019-07-23
      • 2021-08-02
      相关资源
      最近更新 更多