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