关于delete请求,后台接收不到数据
2019-03-19 11:59 CCG波克 阅读(2068) 评论(0) 编辑 收藏 举报在前端用axios需要这样写
/**
* 删除数据
*/
export function del(url, data = {}) {
return axios.delete(url, { data: qs.stringify(data) })
}
在浏览器中传输参数是在Request Payload中的,与以往的formdata不同
后台接收需要额外的方法
后台要想从Request Payload中得到自己想要的数据,就要从流中来获取数据,具体的代码为
ong evalutorId = null;
//从Request Payload中获取数据,从流中来获取数据
ServletInputStream is;
try {
is = request.getInputStream();
int nRead = 1;
int nTotalRead = 0;
byte[] bytes = new byte[10240];
while (nRead > 0) {
nRead = is.read(bytes, nTotalRead, bytes.length - nTotalRead);
if(nRead > 0)
nTotalRead = nTotalRead + nRead;
}
// str为evalutorId=20
String str = new String(bytes, 0, nTotalRead, "utf-8");
String[] split = str.split("=");
evalutorId = Long.parseLong(split[1]);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
参考:https://blog.csdn.net/Your_heart_private/article/details/71436210