Axios 错误:连接 ECONNREFUSED 127.0.0.1:80

chl*_*loy 0 javascript node.js axios

您好,我是 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);
  })
  
Run Code Online (Sandbox Code Playgroud)

先感谢您

小智 5

您使用了一个没有任何方案的 URL,这就是 axios 在 127.0.0.1:80 的本地主机上处理此 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);
})
Run Code Online (Sandbox Code Playgroud)