通过 axios 在 RapidAPI 中调用 Yahoo Finance API 返回错误 500

问题描述 投票:0回答:1

我通过 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 吗?

javascript axios yahoo-finance rapidapi
1个回答
0
投票

发现问题了!

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))
© www.soinside.com 2019 - 2024. All rights reserved.