当我发出发布请求时,React Native返回[未处理的承诺拒绝:TypeError:网络请求失败]

问题描述 投票:0回答:2

[当我在带有Axios的React Native中发出发布请求时,它返回[未处理的承诺拒绝:TypeError:网络请求失败]。这是我的json和axios方法

const credentials= {
NickName: "ricardo.luna",
Password: "123",
AccesoAplicacion: 1,
DerechosRangoInicial: 1000,
DerechosRangoFinal: 1012
}

const loginAxios = () => {
axios
  .post('x.x.x.x/API/users', credentials)
  .then(response => {
    console.log(response.IdUser);
  });
 };
javascript react-native post axios http-post
2个回答
0
投票

只需在.then().catch(error=>{})之后添加以处理拒绝并捕获返回的错误


0
投票

您需要将您的发布参数传递为FormData

let bodyFormData = new FormData();

bodyFormData.set('NickName', 'Fred');
bodyFormData.set('Password', '123');
bodyFormData.set('AccesoAplicacion', 1);
bodyFormData.set('DerechosRangoInicial', 1000);
bodyFormData.set('DerechosRangoFinal', 1012);
© www.soinside.com 2019 - 2024. All rights reserved.