Reputation: 3462
I am trying to get the body of a HttpServletRequest in a String. What's the best elegant way to do so?
Upvotes: 18
Views: 23959
Reputation: 31659
Other way, using Guava:
ByteSource.wrap(ByteStreams.toByteArray(request.getInputStream()))
.asCharSource(Charsets.UTF_8).read()
See also:
Upvotes: 2
Reputation: 3378
Using Apache Commons IO:
String requestStr = IOUtils.toString(request.getInputStream());
Upvotes: 19