【问题标题】:get 401 Unauthorized erro when using rapid api and here are the screenshot of api doc使用 rapidapi 时出现 401 Unauthorized 错误,这里是 api doc 的截图
【发布时间】:2021-03-23 12:57:34
【问题描述】:

这是我调用 api 的代码:

apiBaseURL=${environment.baseUrl}

构造函数(私有 http: HttpClient){ }

getTeams() {

let authToken = {
  "x-rapidapi-key": "ba0a665d73msh8c54a216ac1d6c5p1f80c4jsn312950ace3e0",
  "x-rapidapi-host": "api-football-v1.p.rapidapi.com"
}
const reqHeader = new HttpHeaders({
  'Content-Type': 'application/json',
  'Authorization': `Bearer ${authToken}`
})

return this.http.get('https://api-football- 
v1.p.rapidapi.com/v2/teams/team/33', {headers: reqHeader })

}

【问题讨论】:

    标签: angular api http-status-code-401 rapidapi


    【解决方案1】:

    使用前请务必在 RapidAPI Hub 上订阅 API。这可能是您收到 401 未授权响应的可能原因。

    如果订阅成功后错误仍然存​​在,请尝试添加 x-rapidapi-keyx-rapidapi-host 作为自定义标头。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-26
      • 2016-02-02
      • 1970-01-01
      • 2019-03-16
      • 2016-11-28
      • 1970-01-01
      • 2021-12-11
      • 2021-06-29
      相关资源
      最近更新 更多