简体   繁体   English

React-Native Android“网络请求失败”

[英]React-Native Android 'Network Request failed'

The issue:问题:

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 特有的,因为请求甚至在发送之前就触发了错误,实际上甚至没有发送。

So far I tried:到目前为止,我尝试过:

  • 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 上尝试过

Software versions:软件版本:

  • 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.

相关问题 Android上的React-Native fetch()网络请求失败 - React-Native fetch() Network Request Failed on Android react-native 的“网络请求失败”(即使使用 `android:usesCleartextTraffic=“true”`) - “Network request failed” with react-native (even with `android:usesCleartextTraffic=“true”`) 类型错误:尝试从 android 模拟器访问本地 API 时网络请求失败。 React-Native - TypeError: Network Request Failed when trying to hit local API from android emulator. React-Native react-native提取在具有HTTP远程服务器后端的Android设备上引发“网络请求失败”错误 - react-native fetch throws “Network request failed” error on Android Devices with backend in http remote server React-native Android模拟器 - POST因TypeError失败:网络请求失败 - React-native Android emulator - POST fails with TypeError: Network request failed react-native中的“网络请求失败”和“ XMLHttpRequest.chr.onerror” - “Network request failed” and “XMLHttpRequest.chr.onerror” in react-native Fetch 在 React-Native 0.14 中抛出“网络请求失败” - Fetch throws "Network request failed" in React-Native 0.14 在android上反应本机获取网络请求失败 - react native Fetch Network request failed on android React Native Android 中的网络请求失败 - Network Request Failed in React Native Android 反应原生 android: TypeError: Network request failed - react native android: TypeError: Network request failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM