【问题标题】:Network error using Axios get request in React Native app having Node.js backend在具有 Node.js 后端的 React Native 应用程序中使用 Axios 获取请求的网络错误
【发布时间】:2020-10-19 15:23:02
【问题描述】:

我已经尝试了 Stack Overflow 的一些解决方案,但仍然无法解决这个问题。需要其他解决方案。

 componentDidMount(){
  this.getCar()
}

async getCar() {
  try {
    const response = await axios.get('http://127.0.0.1:8000/topratedcars');
    console.log(response);
  } catch (error) {
    console.error(error);
  }
}

【问题讨论】:

  • 什么是问题?给minimal reproducible example
  • 我在前端使用 axios 来获取 api 数据,这在邮递员中运行良好,但是当我从代码中生成 req 时,它显示网络错误
  • 它没有进入“尝试”块

标签: node.js react-native get axios general-network-error


【解决方案1】:

您好,我认为您可以尝试使用 ngrok 之类的服务将您的本地主机暴露在互联网上,该服务将为您生成一个 url,然后尝试使用该 url 从您的代码发送请求。只需下载并按照此处的说明进行操作:https://ngrok.com/docs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-10
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-24
    • 2017-12-29
    相关资源
    最近更新 更多