首页 > 解决方案 > 在具有 Node.js 后端的 React Native 应用程序中使用 Axios 获取请求的网络错误

问题描述

我已经尝试了 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);
  }
}

标签: node.jsreact-nativegetaxiosgeneral-network-error

解决方案


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


推荐阅读