1

我正在尝试向 api.weatherstack.com 发出 GET 请求(请参阅文档)。

这是我的反应效果挂钩:

useEffect(() => {
      if (country === undefined) return
      console.log(country.name)
      axios
        .get('http://api.weatherstack.com/current', {
            params: {
              access_key: api_key, 
              query: country.name
            }
        })
        .then(response => {
          console.log(response.data)
          setWeather(response.data)
        })
    }, [api_key, country])

但是,每次我运行它时,我都会收到此错误:

{ 代码:105,类型:“https_access_restricted”,信息:“访问受限 - 您当前的订阅计划不支持 HTTPS 加密。” }

通过我的浏览器或 Postman 进行 API 调用非常有效,所以我认为我使用 React 或 Axios 的方式可能存在问题。

此外,这个 API 调用大约有 10% 的时间有效,所以我对为什么也会发生这种情况感到困惑。

4

2 回答 2

0

我认为这是因为您使用的是免费计划

weatherstack.com https 加密

于 2020-07-30T23:35:55.377 回答
0

尝试:

.get("http://api.weatherstack.com/current?access_key=YOUR_ACCESS_KEY&query=country.name)

在第 5 行。

删除第params: {} 6-9 行

于 2022-03-04T00:27:18.897 回答