繁体   English   中英

网络请求失败 - Expo Fetch - React Native

[英]Network Request Failed - Expo Fetch - React Native

我创建了一个 expo 项目,我还在我的机器上构建了一个 nodejs 服务器,get 和 post 请求在 chrome 浏览器和 postman 上按预期工作,不幸的是,仅在 expo 应用程序上出了点问题,fetch 抛出以下错误

Network request failed
- node_modules\whatwg-fetch\dist\fetch.umd.js:473:29 in xhr.onerror
- node_modules\event-target-shim\dist\event-target-shim.js:818:39 in EventTarget.prototype.dispatchEvent
- node_modules\react-native\Libraries\Network\XMLHttpRequest.js:574:29 in setReadyState
- node_modules\react-native\Libraries\Network\XMLHttpRequest.js:388:25 in __didCompleteResponse
- node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:190:12 in emit
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:436:47 in __callFunction
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:26 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:110:17 in __guard$argument_0
* [native code]:null in callFunctionReturnFlushedQueue

我正在运行一个 android 模拟器,服务器可以通过模拟器的浏览器访问,但不能通过 react 应用程序访问。 防火墙被禁用。 从公共网址获取任何内容以正常工作。

任何人都知道为什么我的应用程序(无论是在 android 模拟器还是真正的 ios 设备上运行)不能仅在 expo 客户端中访问服务器,而是可以通过普通浏览器访问。

希望你的问题已经解决了...

如果没有 - 您是否尝试按照文档中的建议从 10.0.2.2(127.0.0.1 指向模拟器环回)进行连接 - > https://developer.android.com/studio/run/emulator-networking

如果已经解决,请分享您是如何解决的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM