【问题标题】:not able to call backend running on localhost in react native无法调用在本地主机上运行的后端以响应本机
【发布时间】:2021-07-18 16:32:44
【问题描述】:

当我对在本地运行的后端路由进行 fetch 调用时,我会在 catch 块中得到响应。

TypeError:网络请求失败

let testLocal = 'http://127.0.0.1:5000/test-817a8/us-central1/app/heartbeat'
fetch(testLocal, {
  method: 'GET',
}).then(res => {
  console.log("success")
  console.log("Form submitted:", res)
}).catch(err => {
  console.log("error occured:" + err)
})

【问题讨论】:

  • 我之前遇到过这个问题,是关于我的安卓模拟器的。我猜模拟器的android版本是4。然后我安装了android 7模拟器,然后错误就消失了。在你的情况下,也许你应该用 localhost 替换 127.0.0.1
  • 使用你的 ipv4 而不是环回地址。

标签: react-native fetch mobile-development


【解决方案1】:

在这个问题中,需要更换IP地址: 您需要使用 IPv4 地址而不是 (127.0.0.1) localhost(类似于:192.168.x.x)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    • 1970-01-01
    • 2017-06-11
    • 2015-12-24
    • 2016-09-16
    • 1970-01-01
    • 2023-04-09
    相关资源
    最近更新 更多