[英]React-Native Android 'Network Request failed'
I have been unable to do fetch()
calls on the Android version of my react-native
app recently, with the error infos being only :我最近无法在我的react-native
应用程序的 Android 版本上执行fetch()
调用,错误信息仅为:
TypeError: Network request failed
at XMLHttpRequest.xhr.onerror (whatwg-fetch.js:504)
at XMLHttpRequest.dispatchEvent (event-target.js:172)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:580)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:394)
at XMLHttpRequest.js:507
at RCTDeviceEventEmitter.emit (EventEmitter.js:190)
at MessageQueue.__callFunction (MessageQueue.js:349)
at MessageQueue.js:106
at MessageQueue.__guard (MessageQueue.js:297)
at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:105)
I tested on iOS and it works perfectly fine.我在 iOS 上测试过,效果很好。 The exact same code on Android will fail no matter what I tried.无论我尝试什么,Android 上完全相同的代码都会失败。
The strangest thing is that sometimes, the Android app will be able to perform 1 or 2 fetch()
calls successfully but after that all the other will fail, or simply absolutely none will succeed.最奇怪的是,有时,Android 应用程序将能够成功执行 1 或 2 次fetch()
调用,但之后所有其他调用都会失败,或者根本没有成功。 I am sure this is specific to Android as the request triggers the error before even being sent, and actually, is not even being sent.我确信这是 Android 特有的,因为请求甚至在发送之前就触发了错误,实际上甚至没有发送。
replacing the server address with its IP用它的 IP 替换服务器地址
setting up a local JSON Server on my computer to fetch()
on it在我的计算机上设置本地 JSON 服务器以在其上fetch()
tried on both an emulator and a physical device在模拟器和物理设备上都试过了
tried on Android 7.0 and Android 9.0在 Android 7.0 和 Android 9.0 上尝试过
react-native: 0.57.8反应原生:0.57.8
react: 16.6.3反应:16.6.3
Ok so I finally managed to fix this.好的,所以我终于设法解决了这个问题。
Unfortunately I don't exactly know what was wrong.不幸的是,我不完全知道出了什么问题。 This whole thing happened while I was trying to setup and configure push notifications for FireBase in react-native.当我尝试在 react-native 中为 FireBase 设置和配置推送通知时,这整件事发生了。 I started all over and now it works.我从头开始,现在它起作用了。 I'm sorry for whoever will experience this issue as well, but the only advice I can give you is to start fresh and read the documentation again.对于同样遇到此问题的人,我很抱歉,但我能给您的唯一建议是重新开始并再次阅读文档。
Good luck !祝你好运 !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.