javascript - 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);
})
先感谢您
解决方案
你使用了一个没有任何方案的 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);
})
推荐阅读
- javascript - 如何在 HTML-CSS-JS 中合并 2 个元素?
- .net - ODP.NET 连接在 Parallel.ForEach 中过早关闭(或关闭两次?)
- local-storage - Chrome 扩展中的 MSAL:安全令牌存储
- visual-studio-code - 奇怪的 CMD - VSCode 行为
- pagespeed-insights - 分数波动:单项63,其他测试97-100
- python - 我可以在 xlsxwriter 中打开现有工作表吗?
- r - 为什么这个 R 代码给我 1 1 0 而不是 3 0 或 1 0 或 3 1 0?
- html - CSS 网格异常对齐
- r - 替换 RMarkdown bookdown pdf-document 中的图形标题前缀
- javascript - 如何使用 Signal R 和 ASP.Net Core 更新单个项目?