[当我在带有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);
});
};
只需在.then().catch(error=>{})
之后添加以处理拒绝并捕获返回的错误
您需要将您的发布参数传递为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);