Created
June 20, 2019 10:10
-
-
Save hackerzhut/e530578d911a98698b9eb0500cff1a9a to your computer and use it in GitHub Desktop.
Get Request Body
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private String getBody(HttpServletRequest request) { | |
| StringBuffer sb = new StringBuffer(); | |
| BufferedReader br = null; | |
| InputStream is = null; | |
| try { | |
| is = request.getInputStream(); | |
| if (is != null) { | |
| br = new BufferedReader(new InputStreamReader(is)); | |
| char[] charBuffer = new char[128]; | |
| int bytesRead = -1; | |
| while ((bytesRead = br.read(charBuffer)) > 0) { | |
| sb.append(charBuffer, 0, bytesRead); | |
| } | |
| } | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } finally { | |
| if (br != null) { | |
| try { | |
| br.close(); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } | |
| return sb.toString(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment