[Vuejs]-How to pass Header + Body in POST api using Vue JS-axios

4👍

The TOKEN Endpoint only accept application/x-www-form-urlencoded and you are sending JSON (because axios only serializes JavaScript objects to JSON)

How to use axios to send application/x-www-form-urlencoded: https://github.com/axios/axios#using-applicationx-www-form-urlencoded-format

here is example with qs library

<script>
HTTP.post(`token`, qs.stringify({
    'grant_type': 'authorization_code',
    'client_id': 'XXXXXXXXXXXXXXXXXXXXXXXXX',
    'redirect_uri': 'http://localhost:8080/callback',
    'code': this.$route.query.code
  }))
  .then(response => {
    console.log('Response: ' + response)
  })
  .catch(e => {
    console.log('Error: ' + e)
  })
</script>

Leave a comment