POST 请求

POST 请求

POST 请求发起一个 POST 请求

axios.post('/user', { firstName: 'Fred', lastName: 'Flintstone' }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });

发起多个并发请求

function getUserAccount() { return axios.get('/user/12345');}function getUserPermissions() { return axios.get('/user/12345/permissions');}const [acct, perm] = await Promise.all([getUserAccount(), getUserPermissions()]);// ORPromise.all([getUserAccount(), getUserPermissions()]) .then(function ([acct, perm]) { // ... });

将 HTML Form 转换成 JSON 进行请求

const {data} = await axios.post('/user', document.querySelector('#my-form'), { headers: { 'Content-Type': 'application/json' }})

Forms​

Multipart (multipart/form-data)

const {data} = await axios.post('https://httpbin.org/post', { firstName: 'Fred', lastName: 'Flintstone', orders: [1, 2, 3], photo: document.querySelector('#fileInput').files }, { headers: { 'Content-Type': 'multipart/form-data' } })

URL encoded form (application/x-www-form-urlencoded)

const {data} = await axios.post('https://httpbin.org/post', { firstName: 'Fred', lastName: 'Flintstone', orders: [1, 2, 3] }, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }})

相关推荐

回顾2002年世界杯罗纳尔多外星人般的传奇表现与辉煌时刻
薇薇安 - 绝区零WIKI
365平台被黑不给出款怎么办

薇薇安 - 绝区零WIKI

📅 10-04 👁️ 707
电信提速攻略
365平台被黑不给出款怎么办

电信提速攻略

📅 07-09 👁️ 2752