【问题标题】:Network Request Failed - Expo Fetch - React Native网络请求失败 - Expo Fetch - React Native
【发布时间】:2020-07-04 04:52:30
【问题描述】:

我正在创建一个 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 应用程序访问服务器。 防火墙被禁用。从公共 url 获取任何内容以正常工作。

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

【问题讨论】:

    标签: node.js react-native express fetch expo


    【解决方案1】:

    希望您的问题已经解决...

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

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

    【讨论】:

      猜你喜欢
      • 2020-11-20
      • 2020-07-23
      • 1970-01-01
      • 2018-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-16
      • 1970-01-01
      相关资源
      最近更新 更多