首页 > 解决方案 > Axios 错误:连接 ECONNREFUSED 127.0.0.1:80

问题描述

您好,我是 nodejs 的新手,当我运行我的应用程序时出现此错误“错误:连接 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);
  })
  

先感谢您

标签: javascriptnode.jsaxios

解决方案


你使用了一个没有任何方案的 URL,这就是为什么 axios 在你的 localhost 上处理这个 URL,即 127.0.0.1:80。只需在网址前添加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);
})

推荐阅读