【发布时间】:2020-07-05 16:31:21
【问题描述】:
我正在尝试访问 本地计算机上的远程 HTTP Api。该 API 在我本地机器上的 Postman 和 Chrome 上运行良好。但是当使用 Expo React Native Fetch 进行 Fetch 调用时,我收到以下错误:
网络请求失败
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 在 setReadyState
node_modules\react-native\Libraries\Network\XMLHttpRequest.js:388:25 在 __didCompleteResponse
node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:190:12 在发射
node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:436:47 在 __callFunction
node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:26 在 __guard$argument_0
node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 在 __guard
node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:110:17 在 __guard$argument_0
[本机代码]:null in callFunctionReturnFlushedQueue**
为了您的信息,我正在尝试使用 expo 客户端在最新的 Android 设备上运行该应用程序。
代码:
componentDidMount() {
const url = (Remote Http URL);
this.setState({
loading: true
});
fetch(url)
.then(res => res.json())
.then(res => {
this.setState({
loading: false,
error: res.error || null,
data1: res
}, () => {
console.log(res);
});
})
.catch(error => {
this.setState({
error,
loading: false
}, () => {
console.log(error);
});
});
}
请帮我解决这个问题。谢谢。
【问题讨论】:
标签: javascript android node.js react-native