I am making a post request to the API but the problem that i see is that the authtoken gets sent in request payload instead of request headers in network tab.
const fetchData =(id,authToken)=>
axios
.post(`${APIUrl}/${id}/math`,{
headers:{
...getAuthHeaderWithContentType(authToken, "JSON")
}
})
.then(resp => (resp && resp.data ? resp.data : null));
The headers should appear in request headers instead of request payload .
Because you post a object what includes headers
field as data
.
axios
official document said: axios.post(url, data, options)
Just add null
or {}
as data
if you do not have any data to post.
const fetchData = (id, authToken) =>
axios
.post(`${APIUrl}/${id}/math`, {}, {
headers: {
...getAuthHeaderWithContentType(authToken, "JSON")
}
})
.then(resp => (resp && resp.data ? resp.data : null));
But, I think use POST
method to get data is not recommended.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments