1public static String getBody(HttpServletRequest request) throws IOException {
2
3 String body = null;
4 StringBuilder stringBuilder = new StringBuilder();
5 BufferedReader bufferedReader = null;
6
7 try {
8 InputStream inputStream = request.getInputStream();
9 if (inputStream != null) {
10 bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
11 char[] charBuffer = new char[128];
12 int bytesRead = -1;
13 while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
14 stringBuilder.append(charBuffer, 0, bytesRead);
15 }
16 } else {
17 stringBuilder.append("");
18 }
19 } catch (IOException ex) {
20 throw ex;
21 } finally {
22 if (bufferedReader != null) {
23 try {
24 bufferedReader.close();
25 } catch (IOException ex) {
26 throw ex;
27 }
28 }
29 }
30
31 body = stringBuilder.toString();
32 return body;
33}
1// Read from request
2 StringBuilder buffer = new StringBuilder();
3 BufferedReader reader = request.getReader();
4 String line;
5 while ((line = reader.readLine()) != null) {
6 buffer.append(line);
7 }
8 String data = buffer.toString()