我通过 RapidAPI 订阅了 Yahoo Finance API,并且我使用 axios 调用该 API,如下所示:
const apiKey = [MY API KEY]
const apiURL = 'https://yahoo-finance127.p.rapidapi.com'
const headers = {
'x-rapidapi-key': apiKey,
'x-rapidapi-host': apiURL
}
axios.get(apiURL + '/price/NVDA', { headers: headers })
.then(response => console.log(response.data.data))
.catch(error => console.error(error.message))
知道为什么会返回错误 500 吗?
发现问题了!
RapidAPI 调用不需要调用标头中的
https://
,只需要 URL 域本身。解决方案:
const apiKey = [MY API KEY]
const apiURL = 'yahoo-finance127.p.rapidapi.com'
const headers = {
'x-rapidapi-key': apiKey,
'x-rapidapi-host': apiURL
}
axios.get('https://' + apiURL + '/price/NVDA', { headers: headers })
.then(response => console.log(response.data.data))
.catch(error => console.error(error.message))