0

I use token authentication to communicate between React and DRF. I can make GET request using below token but can not POST data to server with payload.

    axios.post('URL',
    {
      headers: {'Authorization': 'Token 83d1892877db7950c1c5a818cbb6ca738e53f90b'} 

})
      .then(function (response) {
       console.log(response)
      })
      .catch(function (error) {
        console.log(error);
      }) 

I get error 500 from Django server when posting above.But with same URL and Token I could successfully execute POST request in Postman.

I want to add a data with the axios POST request, the data is {name:'myname'}.

Thanks in advance

1 Answer 1

2

Headers should be the 3rd parameter in your call to axios.post, you are passing them as 2nd parameter which is the body.

axios.post(URL, data, {
  headers: {
    'Authorization': 'Token 83d1892877db7950c1c5a818cbb6ca738e53f90b'
  }
})
Sign up to request clarification or add additional context in comments.

Comments

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.