Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

axios giving [AxiosError: Network Error] in react native

i am new to react native and i am trying to submit a api using axios in react native but i am getiign [AxiosError: Network Error] i dont know what this is or how i can fix this

 function getdata() {
 
    const Data = {
      babyname: babyname,
      password: name,
      email: email,
      phone: nuber,

      period: mydate,
    };

    console.log(Data);
  
    axios({
      method: 'POST',
      url: 'http://127.0.0.1:8000/api/details/',
      data: Data,
    })
      .then(function (response) {
        console.log(response.data);
      
      })
      .catch(function (error) {
        console.log(error);
      });

i used the default inspect elemt in react native and have network tab opened enter image description here

enter image description here enter image description here

enter image description here

enter image description here

like image 666
vivek kn Avatar asked Sep 16 '25 13:09

vivek kn


1 Answers

I think the problem is from Ip that you are trying to get connected

it seems that you are using an android emulator, so 127.0.0.1 is not the IP that runs in Postman

if 127.0.0.1 is your localhost, changing that to 10.0.2.2 might fix your problem

axios({
  method: 'POST',
  url: 'http://10.0.2.2:8000/api/details/',
  data: Data,
})
like image 178
Ali Sattarzadeh Avatar answered Sep 19 '25 06:09

Ali Sattarzadeh