2

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 .

Vikas Singh
  • 1,129
  • 10
  • 20
dfsdigging
  • 317
  • 3
  • 13
  • According to docs on gitthub, the method signature is `axios.post(url[, data[, config]])` - you are passing your headers as part of the data, they should be part of config instead. – 04FS Mar 19 '19 at 11:30

1 Answers1

2

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.

hoangdv
  • 9,655
  • 3
  • 13
  • 34