我正在尝试访问本地机器上的远程HTTP。这个API在邮递员和我的本地机器的Chrome上运行得很好。但是,在使用世博进行提取调用时,使用本机获取响应时,我会得到以下错误:
网络请求失败
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在发射
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
本机代码: callFunctionReturnFlushedQueue**中的null
关于您的信息,我正在尝试使用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);
});
});
}请帮我解决这个问题。谢谢。
发布于 2020-05-02 18:36:01
我找到的唯一解决这个问题的方法是将我将获取的url作为主机设置到我的IP地址(因为我的电话响应本机运行方式与后端不同)。最后,将后端设置为0.0.0.0:8080似乎解决了这个问题。至少是暂时的。
https://stackoverflow.com/questions/60843583
复制相似问题