地址栏传过来或者是postman的
这种方式传的参数进到后台接收都是
a=a&b=b这样的
现在需要获取参数值先得把字符串转成json
直接转会报错的
InputStream body1 = request.body;
if (body1 != null) {
byte[] bytes = new byte[0];
bytes = new byte[body1.available()];
body1.read(bytes);
String body = new String(bytes);
String[] numberArray = body.split("&");
String bodyRe = "";
int count = 0;
for (String s : numberArray) {
if (s.contains("=")) {
if (count == 0) {
bodyRe = s;
} else {
bodyRe = bodyRe + "&" + s;
}
count = count + 1;
}
}
bodyRe = bodyRe.replaceAll("=", "\":\"");
bodyRe = bodyRe.replaceAll("&", "\",\"");
bodyRe = bodyRe.replaceAll("%2B", "+");
bodyRe = bodyRe.replaceAll("%2F", "/");
bodyRe = bodyRe.replaceAll("%3D", "=");
bodyRe = "{\"" + bodyRe + "\"}";
jsonobj = JSONObject.parseObject(bodyRe);
}