我正在编程一个使用服务的react native应用程序,如果该服务在发送报头和正文时可以在POSTMAN中使用(如果它可以工作的话),但是当我尝试使用react native的访存和axios使用时,它返回状态406没有返回任何其他响应,我不知道我是否在功能中遗漏了某些东西,还是感谢某人?postman consume postman body status 200 fetch function或axios function packagejson
INSIDE POSTMAN:
(key :value)
Headers:
X-Api-Key: 123456754321345
Body:
username: a@b.com
password: password
and the service return
{
"status": true,
"message": "Login succeed",
"data": {
"id": "3",
"email": "a@b.com",
"oauth_uid": null,
"oauth_provider": null,
"pass": "4f06434a830e21146a8ce3444fee870a60cb1ebb92871589c6f5bc8a22284925",
"username": "username",
"full_name": "Nombre Apellido",
"avatar": "20180806212239-74-512.png",
"banned": "0",
"last_login": "2018-08-17 21:32:06",
"last_activity": null,
"date_created": "2018-08-06 21:22:39",
"forgot_exp": null,
"remember_time": null,
"remember_exp": null,
"verification_code": null,
"top_secret": null,
"ip_address": "186.3.71.211",
"puntoventa": "",
"idciudad": "0",
"idsector": "0",
"direccion": "",
"latitud": null,
"longitud": null,
"telefono": null,
"idcliente": "0"
},
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkYXRhIjp7ImlkIjoiMyJ9LCJpYXQiOjE1MzQ1NTk1MjcsImV4cCI6MTUzNDU4MTEyN30.Tbs9MYIu8hR-TDjxnUlHs8j64JoXquRJYD04AUvZNmu4"
}
IN REACT NATIVE:
INSIDE package-json
"dependencies": {
"axios": "^0.18.0",
"babel-preset-react-native": "^4.0.0",
"eslint": "^5.3.0",
"native-base": "^2.7.2",
"react": "16.4.1",
"react-native": "^0.55.4",
"react-navigation": "^2.8.0"
},
inside Login.js
componentDidMount() {
this.getLogin();
}
FETCH FUNCTION:
getLogin = () => {
const formdata = new FormData();
formdata.append('username', 'a@b.com');
formdata.append('password', 'password');
fetch("http://url/api/user/login", {
method: 'POST',
headers: {
'X-Api-Key': '123456754321345'
},
body: formdata
})
.then(response => {
console.log(
'response', response
);
})
.done();
};
------------------------
OR WITH AXIOS
componentDidMount() {
this.getLogin2();
}
AXIOS FUNCTION
-------------------//I TRIED WITH BOTH WITHOUT RESULT
getLogin2 = () => {
let formData = new FormData();
formData.append("usuario", 'prueba@yopmail.com');
formData.append("password", 'prueba1');
console.log('data form', formData);
const config = {
headers: {
'X-Api-Key': '2C36AB90F09F447D3633DB75812C30A3'
}
};
axios.post('http://gestiona-desarrollo.000webhostapp.com/api/user/login', formData, config).then(
response => {
console.log({ response });
},
error => {
console.log({ error });
}
);
}
在两种情况下,当我运行调试模式时,两个选项的状态均为406