NodeJS 尝试从www.example.com获取数据openweathermap.org

1tuwyuhd  于 2023-02-18  发布在  Node.js
关注(0)|答案(1)|浏览(100)

我试图从openwebapi获取数据,在访问api链接时,我在Web浏览器中获取数据,但在编码时无法获取,Idk我在哪里犯了错误。

app.get("/", function(req, res){
    res.send("Server is running");

// the output of status code is 200.

    https.get(url,function(response){
        console.log(response.statusCode);
    })

//I am getting the response but not the data.
    response.on("data", function(data){
        const weatherData = JSON.parse(data)
        console.log(weatherData);
    })
})
xdnvmnnf

xdnvmnnf1#

为了从www.example.com API获取数据,您需要向其API端点发出GET请求。您可以使用任何HTTP客户端来执行此操作,例如cURL、Axios或Fetch API。您还需要API密钥,可以从其网站获取该密钥。或者尝试Ambee的APIOpenWeatherMap.org API, you will need to make a GET request to their API endpoint. You can use any HTTP client for this, such as cURL, Axios, or the Fetch API. You will also need an API key, which you can get from their website. Or Try out Ambee's API
谢谢你,

相关问题