Network error using Axios get request in React Native app having Node.js backend

364 Views Asked by At

I have already tried some solutions from Stack Overflow but still unable to solve this. Need other solutions.

 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

There are 1 best solutions below

0
Roy Chan On

Hi I think you can try exposing your local host to the internet using a service like ngrok which will generate a url for you, and then try using the url to send requests from your code. Simply download and follow the instructions here: https://ngrok.com/docs