axios提交的表单转换成application/x-www-form-urlencoded
当后台限定必须用application/x-www-form-urlencoded数据格式提交表单时import Qs from "qs";//需要转换的数据datamethod: "POST",headers: { "content-type": "application/x-www-form-urlencoded" },data: Qs.stringify(dataa),以下为axios操作的
·
当后台限定必须用application/x-www-form-urlencoded数据格式提交表单时
import Qs from "qs";
//需要转换的数据data
method: "POST",
headers: { "content-type": "application/x-www-form-urlencoded" },
data: Qs.stringify(data),
以下为axios操作的补充
拦截器的post请求可以添加Content-Type头部,若后台已经写死,不传也可以
const instance = axios.create({
baseURL: 'http://39.108.147.139:9091',
timeout: 3000
})
instance.interceptors.request.use(function (config) {
if(config.method == 'post'){
config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
}
return config;
}, function (error) {
// 做一些与请求错误
return Promise.reject(error);
});
更多推荐
已为社区贡献4条内容
所有评论(0)