I'm trying to pass datas to my back-end Node js server with my react native app. And for that i'm using axios.
onTrigger = () => {
const params = JSON.stringify({
"username": "Name",
"password": "Pass",
});
axios.post('http://192.168.1.36:8080/api/signin',params)
.then(function (response) {
this.props.navigation.navigate('Principal')
})
.catch(function (error) {
console.log(error);
});
}
But it's not doing nothing. My server is not detecting nothing.
But when i'm trying with postman with the same body and the same datas, it's working.
With Postman, i have a reaction from my server
I would like to know if anyone have an idea why my axios is not working but if i'm doing the same in postman, it's working.
try like this. it works for me
const params = JSON.stringify({
"username": "Name",
"password": "Pass",
});
var config = {
method: 'post',
url: 'http://192.168.1.36:8080/api/signin',
headers: {
'Content-Type': 'application/json'
},
data : params
};
axios(config)
.then(function (response) {
this.props.navigation.navigate('Principal')
})
.catch(function (error) {
console.log(error);
});
Please try this.
const apiClient = axios.create({ baseURL: 'http://192.168.1.36:8080/, timeout: 10000, headers: {'Content-Type': 'application/json'}, });
const params = { username: "Name", password: "Pass", });
apiClient.post('api/signin',params).then(() => {})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.