Skip to content

Instantly share code, notes, and snippets.

@barhoring
Forked from akexorcist/index.js
Created October 13, 2019 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barhoring/014919148fb3490f5319aaf75a074e33 to your computer and use it in GitHub Desktop.
Save barhoring/014919148fb3490f5319aaf75a074e33 to your computer and use it in GitHub Desktop.
Axios post method requesting with x-www-form-urlencoded content type
const axios = require('axios')
const qs = require('querystring')
...
const requestBody = {
name: 'Akexorcist',
age: '28',
position: 'Android Developer',
description: 'birthdate=25-12-1989&favourite=coding%20coding%20and%20coding&company=Nextzy%20Technologies&website=http://www.akexorcist.com/',
awesome: true
}
const config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}
axios.post(url, qs.stringify(requestBody), config)
.then((result) => {
// Do somthing
})
.catch((err) => {
// Do somthing
})
@barhoring
Copy link
Author

For PATCH verb do axios.patch(url, stringify(requestBody), headers)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment