java后台得到request payload请求中的json请求参数

private String getRequestPayload(HttpServletRequest req) {
StringBuilder sb = new StringBuilder();
try(BufferedReader reader = req.getReader();) {
char[]buff = new char[1024];
int len;
while((len = reader.read(buff)) != -1) {
sb.append(buff,0, len);
}
}catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}

调用该方法得到json字符串,解析json字符串即可获取所需参数。

转载于:https://www.cnblogs.com/abstracting/p/10592016.html

你可能感兴趣的:(java后台得到request payload请求中的json请求参数)