Axios Post Form Data

Axios Post Form Data

安裝套件

1
2
3
npm init
npm install axios
npm i qs

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const axios = require('axios');
const qs = require('qs');

let formdata = qs.stringify({
Name: 'Andy',
Age : 18
});

axios({
method: 'post',
url: 'Your Url',
data: formdata,
config: { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }
})
.then(function (response) {
//handle success
console.log(response.data);
})
.catch(function (response) {
//handle error
console.log(response);
});

參考