1
votes

I'm new in react native and try to request post Api with axios but the response is request failed with status code 400

changePress = async () => {
    console.log(this.state.user)
    let data = await {
        'name': this.state.user.name,
        'email': this.state.user.email,
        'password': this.state.user.password
    }
    let config = await {
        'headers': {
            'Content-Type':'application/json'
        }
    }
    try{
        await Api.post('/register', data, config)
        .then(res => {
            console.log(res);
            console.log(res.data);
        })
    }
    catch(err){
        console.log(err)
    }
}

Request failed with status code 400

1

1 Answers

2
votes

A little late but can help others. You must have an error in your webserver, the request was created but the server responded with error 400.

You can access error.response.data

 axios.post('/').then(response => {
     console.log(response.data);
 }).catch(error => {
     console.log(error.response.data);
 });