application/x-www-form-urlencoded
最常见的POST编码方式。在nodejs中我们可以使用querystring中间件对参数进行分离。
import axios from 'axios';
import qs from 'qs'
let data={name:'张三',age:18};
axios.post('url',qs.stringify(data))
.then(res=>{
console.log('返回数据:',res)
})
控制台显示”:各个参数用&符隔开

multipart/form-data
一般表单上传文件时用这种形式
import axios from 'axios';
let data=new FormData();
data.append('name','张三');
data.append('age',18);
axios.post('url',data)
.then(res=>{
console.log('返回数据:',res)
})
控制台显示:

application/json
axios默认的提交方式。如果使

本文介绍了axios中POST请求的三种content-type:application/x-www-form-urlencoded(常用,适合参数简单的情况)、multipart/form-data(用于文件上传)、application/json(默认方式,传递JSON字符串)。同时,解释了在跨域请求时,浏览器会先发送OPTIONS预处理请求来检查服务器是否允许该跨域操作。
最低0.47元/天 解锁文章
1589

被折叠的 条评论
为什么被折叠?



