简体   繁体   English

axios 在本机反应中给出 [AxiosError: Network Error]

[英]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我是 React Native 的新手,我正在尝试在 React Native 中使用 axios 提交 api,但我很烦 [AxiosError: Network Error] 我不知道这是什么或如何解决这个问题

 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我在 React Native 中使用了默认的检查元素,并打开了网络选项卡在此处输入图像描述

在此处输入图像描述 在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

I think the problem is from Ip that you are trying to get connected我认为问题出在您尝试连接的 Ip

it seems that you are using an android emulator, so 127.0.0.1 is not the IP that runs in Postman看来您使用的是 android 模拟器,所以 127.0.0.1 不是在 Postman 中运行的 IP

if 127.0.0.1 is your localhost, changing that to 10.0.2.2 might fix your problem如果 127.0.0.1 是您的本地主机,将其更改为 10.0.2.2 可能会解决您的问题

axios({
  method: 'POST',
  url: 'http://10.0.2.2:8000/api/details/',
  data: Data,
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM