I am trying to get the body of a HttpServletRequest in a String. What's the best elegant way to do so?
2 Answers
Using Apache Commons IO:
String requestStr = IOUtils.toString(request.getInputStream());
Comments
Other way, using Guava:
ByteSource.wrap(ByteStreams.toByteArray(request.getInputStream()))
.asCharSource(Charsets.UTF_8).read()
See also:
request.getInputStream()and stackoverflow.com/questions/309424/…