Home > Blockchain >  React native Axios post request works in iOS simulator but not physical phone
React native Axios post request works in iOS simulator but not physical phone

Time:11-02

Currently adding a signUp request in the client

  const { email, password } = params;
  console.log(params);
  const response = await axios.post('http://localhost:8080/api/v1/auth/register', { email: email, password: password });

Which works in simulator but not the iPhone. Any reason that might be? The request also works on postman

CodePudding user response:

You could either configure your web-server to run on an IP that is accessible within the network or you could use a tool like ngrok to expose your web-server to the internet (though that's creating a security risk).

You'll also need to make sure that you're not using localhost as the API base URL otherwise your phone is going to try and send the request to itself and fail.

  • Related