即使在设置了API密钥和用户名到我的请求头后,我仍然收到错误的CSRF

我正在尝试发出一个 POST 请求,我已经设置了它的标头和内容,但它没有给我正确的结果:

export default async function postNewTopic(req, res) {

    axios.post(`url/posts.json?title="${req.query.title}"&raw=${req.query.content}&category=1`, {

    headers: {

      "Api-Key":  token ,

      "Api-Username": {My key}

    }})

    .then(function (response) {

      res.json(response.data);

    })

    .catch(function (error) {

      const err = error?.response?.data || error;

      res.status(error.status ||  error.statusCode || +error.code || 500).json(err)

    })

}

这是我的前端代码:

const createTopic = () => {

    axios.post(`api/post-new?title=${title}&raw=${content}&category=1`, {

        headers: {

          "Authorization": 'Bearer' + "",

          "Api-Key":  token ,

          "Api-Username": ""

        }})

    .then(function (response) {

      res.json(response.data);

    })

    .catch(function (error) {

      const err = error?.response?.data || error;

      console.log(error.response.data)

    })

  }

您的 API 密钥应该是 API 密钥,用户名应该是用户名。看起来您将 API 密钥作为用户名发送了?

不,不,它只在示例中,我已将其删除。但我已放入 api 密钥和 api 用户名,get 函数正在工作。