2
votes

I am trying to login through oauth/tokens from my React Native project. I have tested with POSTMAN When i send the data from axios it works well. But when i try to send from my app it gives me Error: Request failed with status code 400 my code is :

axios({
method: 'post',
url: 'http://183.172.100.84:8000/oauth/token',
headers: { 
    'Accept': 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
},
data: {
    client_id : '2',
    client_secret : 'secret',
    grant_type : 'password',
    email : this.state.userEmail,
    password : this.state.userPassword
}
})
.then((response) => {
console.log(response.data);
})
1
Change your Content-Type to application\json and try againreisdev

1 Answers

0
votes

I've solved the problem in this way:

 axios({
method: 'post',
url: 'http://183.172.100.84:8000/oauth/token',
headers: { 
    'Accept': 'application/json',
        'Content-Type': 'application/json; charset=utf-8'
},
data: 'client_id=2&client_secret=secret&grant_type=password&email=' + this.state.userEmail+'&password='+this.state.userPassword    
})
.then((response) => {
console.log(response.data);
})

Seems Axios have some problem to process the data in json format.

If you use Webpack you must also configure the proxy.