Express 未将x-access-token添加到POST请求中

Express 未将x-access-token添加到POST请求中,express,http,axios,jwt,jwt-auth,Express,Http,Axios,Jwt,Jwt Auth,我使用Redux actions的Axios调用来处理请求或创建资源时的用户身份验证/授权。我已经成功地完成了令牌的所有创建/存储/签名。当用户对资源发出GET请求时,标头的传递方式如下: return axios.get('applicants/', { headers: authHeader() }).then(result => { const applicants = [] result.data.forEach(item =>

我使用Redux actions的Axios调用来处理请求或创建资源时的用户身份验证/授权。我已经成功地完成了令牌的所有创建/存储/签名。当用户对资源发出GET请求时,标头的传递方式如下:

        return axios.get('applicants/', { headers: authHeader() }).then(result => {
        const applicants = []
        result.data.forEach(item => {
            applicants.push(item)
        })
而且效果很好。标头包含“x-access-token”,这是它应该包含的内容。不起作用的是当我发表这样的帖子时:

        return axios.post('applicants/create', { headers: authHeader() })
        .then(result => {
            dispatch(_addApplicants(result.data))
        })
“x-access-token”未包含在标头中。同一个函数为两个路由提供了令牌,因此我确信它与不同的HTTP谓词有关。有人有什么想法吗

获取时的标题:

{
  host: 'localhost:3000',
  connection: 'keep-alive',
  accept: 'application/json, text/plain, */*',
  'x-access-token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVmNGJkMTRhMzcwOGNiNTViMDhmOGM1ZCIsImlhdCI6MTU5ODgwOTI0OCwiZXhwIjoxNTk4ODk1NjQ4fQ.7k4xi3kPo-aKyOf_5GNVv3pjO_WsIZwg8Ja1MgwfJCg',
  'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36',
  origin: 'http://localhost:8080',
  'sec-fetch-site': 'same-site',
  'sec-fetch-mode': 'cors',
  'sec-fetch-dest': 'empty',
  referer: 'http://localhost:8080/',
  'accept-encoding': 'gzip, deflate, br',
  'accept-language': 'en-US,en;q=0.9',
  'if-none-match': 'W/"2-l9Fw4VUO7kr8CvBlt4zaMCqXZ0w"'
}
邮头:

{
  host: 'localhost:3000',
  connection: 'keep-alive',
  'content-length': '204',
  accept: 'application/json, text/plain, */*',
  'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36',
  'content-type': 'application/json;charset=UTF-8',
  origin: 'http://localhost:8080',
  'sec-fetch-site': 'same-site',
  'sec-fetch-mode': 'cors',
  'sec-fetch-dest': 'empty',
  referer: 'http://localhost:8080/',
  'accept-encoding': 'gzip, deflate, br',
  'accept-language': 'en-US,en;q=0.9'
}

您将头作为第二个参数传递给
axios.post
,但实际上它应该是第三个参数。第二个参数是
数据

    axios.post(
        "/applicants/create",
        {}, // add empty object or null here as second argument
        {
          headers: authHeader()
        }
      })

非常感谢你。现在效果很好。