Reputation: 1735
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
Upvotes: 0
Views: 414
Reputation: 6280
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'
}
})
Upvotes: 2