【问题标题】:React Axios get call doesn't work with authorization headerReact Axios get call 不适用于授权标头
【发布时间】:2021-05-11 13:50:28
【问题描述】:

我正在开发一个需要授权的 Axios get in the react。 在我添加授权之前,它运行良好,在我在后端和前端添加授权头之后,它有CORS错误。我在邮递员中尝试了 get 调用,它非常有效。所以我认为应该是Axios在前端获取代码。 这是axios获取代码:

async sendGetRequest(variable) {
        return new Promise((resolve, reject) => {
            let AuthStr = 'token';
            console.log(typeof(AuthStr)); => the type is String
            Axios.get(`url/${variable}`,{
                header:{
                    'Authorization': AuthStr
                }
            })
                .then(res => {
                    resolve(res.data)
                }
                );
        })
    }

我不确定这是否错了,看起来对我来说不错。 这是我的邮递员结果。(我隐藏了网址)

【问题讨论】:

  • 应该是标题,你在末尾缺少's'

标签: reactjs axios header authorization


【解决方案1】:

我自己关闭了这篇文章。 因为我写错了 应该是

headers:{
          'Authorization': AuthStr
      }

希望对其他人有所帮助。

【讨论】:

    猜你喜欢
    • 2018-10-12
    • 2019-11-11
    • 2021-07-22
    • 1970-01-01
    • 2017-05-22
    • 2018-11-01
    • 2018-04-13
    • 1970-01-01
    • 2019-04-11
    相关资源
    最近更新 更多