赞
踩
1、先设置后台servlet页面的参数:
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
response.setContentType("text/json; charset=utf-8");
2、AXIOS发起请求需要加入的参数。特别注意Content-Type的值一定要’application/x-www-form-urlencoded’
由于Tomcat对于Content-Type multipart/form-data(文件上传)和application/x-www-form-urlencoded(POST请求)做了“特殊处理”。
//POST文本数据
'Content-Type': 'application/x-www-form-urlencoded',
//POST文件
Content-Type multipart/form-data
axios({
method: 'post',
url: 'http://10.0.1.41:8080/KQ/userControl',
data: {
userid: that.postUserID,
},
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
})
.then(function (response) {
console.log(response);
})
.catch(function (err) {
console.log(err);
});
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。