1

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 Answer 1

2

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);
 });
Sign up to request clarification or add additional context in comments.

2 Comments

YOU SAVE MY DAY :))
I'm glad it was useful!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.