【问题标题】:Browser get request 404'd but works with Postman app浏览器获取请求 404,但适用于 Postman 应用程序
【发布时间】:2019-12-20 12:52:13
【问题描述】:

标题说明了一切,尝试使用 openweather api 检索一些数据。

它在 Postman 上运行良好,但是在本地环境中使用 vanillaJS 时,我在控制台中收到错误消息

ERROR: GET http://127.0.0.1:5500/api.openweathermap.org/data/2.5/forecast?id=2193733&appid=MYAPIKEY 404 (Not Found)

我的代码是这样的

axios.get(`api.openweathermap.org/data/2.5/forecast?id=2193733&appid=MYAPIKEY`)
         .then(response => {
             console.log(response);
         })

有什么想法吗?

【问题讨论】:

  • 网址中缺少协议。查看请求在您的错误中的去向。它会发送到您的服务器而不是 api

标签: javascript html browser axios postman


【解决方案1】:

您在运行 axios 的应用上收到请求。

试试axios.get('http://api.openwheather...'),它应该可以工作

【讨论】:

  • 谢谢伙计,我还必须注意,这也解决了 ip 地址的问题。我在做 xxx.xxx.xxx.xxx/something 并在 ip 前添加 http:// 解决了问题!
猜你喜欢
  • 1970-01-01
  • 2018-03-25
  • 2021-05-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多