【发布时间】:2021-01-07 10:06:14
【问题描述】:
我有一个使用 HERE 地理编码 API 的 React 应用程序。我有一个 axios 请求来检索纬度和经度,但它没有像预期的那样工作。该请求在我的应用程序中不起作用
return axios.get(`https://geocode.search.hereapi.com/v1/geocode?q=${address}&apiKey=myAPIKey`)
我遇到了 401 错误。 Bearer token invalid. Bearer missing or bearer value missing. 如果我在浏览器中打开一个新选项卡并粘贴 url https://geocode.search.hereapi.com/v1/geocode?q=${address}&apiKey=myAPIKey 它工作正常,我会得到我需要的结果。
我尝试使用授权标头
const config = {
headers: {
'Accept': 'application/json',
'Authorization': `apiKey myAPIKey`,
}
};
return axios.get(`https://geocode.search.hereapi.com/v1/geocode?q=${address}&apiKey=myAPIKey`,config)
在 Authorization 标头中,我尝试使用 Bearer 和 Basic 而不是 apiKey
在有关如何创建 API 密钥以及如何使用它的文档中,我唯一需要做的就是我已经完成的工作。我创建了一个项目、一个 API 密钥并在我的请求中使用它。
【问题讨论】:
-
您好,请尝试将标题设置为“标题:{}”?
标签: reactjs geocoding here-api