axios未获取响应数据

cczfrluj  于 2023-01-13  发布在  iOS
关注(0)|答案(1)|浏览(220)

下面是通过axios获取数据的代码,当我点击浏览器中的实际url时,它会显示响应。

{"location":{"name":"Ipoh","region":"Perak","country":"Malaysia","lat":4.58,"lon":101.08,"tz_id":"Asia/Kuala_Lumpur","localtime_epoch":1673526754,"localtime":"2023-01-12 20:32"},"current":.....


const axios = require("axios");
const weatherResponse = axios.get("https://api.weatherapi.com/v1/current.json?key=11&q=49.37.42.66&aqi=yes", {
headers: { "Content-Type": "application/json" }
}
    );
console.log("aasdasd");
console.log(weatherResponse.data);
console.log("cvghcgh");
6mw9ycah

6mw9ycah1#

我认为这是一个不同步的问题。
下面是一个示例,说明如何执行此操作:

async function getAxios() {
    const axios = require("axios");
    return await axios.get("https://api.weatherapi.com/v1/current.json?key=11&q=49.37.42.66&aqi=yes", {
        headers: {"Content-Type": "application/json"}
    });
}

console.log("aasdasd");
console.log(getAxios());
console.log("cvghcgh");

回应

{
  "error": {
    "code": 2008,
    "message": "API key has been disabled."
  }
}

我想我们需要发布一个新的API密钥。

相关问题