Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何使用Axios发送承载令牌_Reactjs_Api_Rest_Axios - Fatal编程技术网

Reactjs 如何使用Axios发送承载令牌

Reactjs 如何使用Axios发送承载令牌,reactjs,api,rest,axios,Reactjs,Api,Rest,Axios,在后端,我看到了这个代码段,但它没有得到我发送的授权令牌 const token = req.header("bearer-token"); 这是我发送不记名代币的前端代码 const getProfile = (email, token) => { console.log(email, token); const config = { headers: { Accept: "applica

在后端,我看到了这个代码段,但它没有得到我发送的授权令牌

const token = req.header("bearer-token");
这是我发送不记名代币的前端代码

    const getProfile = (email, token) => {
      console.log(email, token);
      const config = {
        headers: {
          Accept: "application/json",
          "Content-Type": "application/json",
          Authorization: `Bearer ${token}`,
        },
      };
      return new Promise((resolve, reject) => {
        axios
          .get(`/user/getProfile`, {email}, config)
          .then((response) => {
            console.log(response);
            resolve(response);
  })
      .catch((err) => reject(err));
  });
};

在这种情况下,请帮助我如何发送Berer令牌?

当您在
授权
标头中发送承载令牌时,您正在请求具有名称
承载令牌
的标头

const-token=req.headers['bearer-token']
更改为:

const token = req.headers['authorization']

这应该可以很好地工作。

您发送“授权”,但查找“承载令牌”?您好,谢谢您的回复。这很好,但我不能改变。因为那是别人的密码。因此,我必须继续使用const-token=req.headers['bearer-token']将
Authorization
header更改为
bearer-token
。即使这样也行。而且,头不区分大小写。这样做了吗,但仍然不起作用在
${token}