How to send axios request to localhost?

I am currently trying to send an API request from a mobile app to a django server running on my computer. I am receiving a network error every time I try and send the request, regardless of the different headers I use (I am new to this so my headers could be totally wrong).

Here is the request I am sending:

export async function requestPrediction(img) {
  const url = 'http://127.0.0.1:8000/v1/predict/';

  const data = new FormData();

  data.append('file', {
    uri: img,
    type: 'image/jpeg',
    name: 'imageName'
  });

  try {
    console.log(url, data);
    let resp = await Axios.post(url, data, {
      headers: {
        'accept': 'application/json',
        'Accept-Language': 'en-US,en;q=0.8',
        'Content-Type': `multipart/form-data; boundary=${data._boundary}`,
      }
    });
    console.log('######################n','ACTION_RESULTS_SUCCESS',resp.data);
  } catch(error) {
    console.log('######################n','ACTION_RESULTS_ERROR', error);
  }
}

I am pretty certain the URL I am sending to is the right address. When I type that URL in on my computer while the server is running I do not receive an error that the page wasn’t found. Thanks for the help. I can post any server-side code that might be necessary.

Answer

This address 'http://127.0.0.1' can only be accessed by your computer.

To access your Django server from your mobile device you need to use your computer’s IP address with that port

Make sure your mobile is connected to the same Wifi as your computer.

Replace 'http://127.0.0.1' with your IP address

so it looks something like this

https://IP_ADDRESS:8000/v1/predict/'

Follow this guide to find your Mac’s IP address