Axios错误:连接ECONNREFUSED 127.0.0.1:80



你好,我是nodejs的新手,我在运行应用程序时遇到了这个错误"错误:connect ECONNREFUSED 127.0.0.1:80"这是我的代码

const axios = require('axios')
const url = 'api.openweathermap.org/data/2.5/weather?q=London,uk&appid=4dd23b28fb57078c0d5ec9c653e203b2'
axios.get(url)
.then((response) =>{
console.log(response)
})
.catch(function (error) {
console.log(error);
})

提前感谢

您使用了一个没有任何方案的URL,这就是axios在您的本地主机127.0.0.1:80上处理此URL的原因。只需在url之前添加http://https://即可。

const axios = require('axios')
const url = 'https://api.openweathermap.org/data/2.5/weatherq=London,uk&appid=4dd23b28fb57078c0d5ec9c653e203b2'
axios.get(url)
.then((response) =>{
console.log(response)
})
.catch(function (error) {
console.log(error);
})

最新更新