Skip to content

Instantly share code, notes, and snippets.

@hackerzhut
Created June 20, 2019 10:10
Show Gist options
  • Select an option

  • Save hackerzhut/e530578d911a98698b9eb0500cff1a9a to your computer and use it in GitHub Desktop.

Select an option

Save hackerzhut/e530578d911a98698b9eb0500cff1a9a to your computer and use it in GitHub Desktop.
Get Request Body
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