在具有Node.js后端的React Native应用中使用Axios获取请求时出现网络错误

时间:2020-06-29 12:49:13

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

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

1 个答案:

答案 0 :(得分:0)

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