【发布时间】: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