首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >响应本机获取远程Http请求引发网络请求失败(在Android设备上)

响应本机获取远程Http请求引发网络请求失败(在Android设备上)
EN

Stack Overflow用户
提问于 2020-03-25 05:50:59
回答 1查看 798关注 0票数 1

我正在尝试访问本地机器上的远程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设备上运行该应用程序。

代码:

代码语言:javascript
复制
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);
      });
    });
}

请帮我解决这个问题。谢谢。

EN

回答 1

Stack Overflow用户

发布于 2020-05-02 18:36:01

我找到的唯一解决这个问题的方法是将我将获取的url作为主机设置到我的IP地址(因为我的电话响应本机运行方式与后端不同)。最后,将后端设置为0.0.0.0:8080似乎解决了这个问题。至少是暂时的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60843583

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档