Get the POST request body from HttpServletRequest Get the POST request body from HttpServletRequest java java

Get the POST request body from HttpServletRequest


In Java 8, you can do it in a simpler and clean way :

if ("POST".equalsIgnoreCase(request.getMethod())) {   test = request.getReader().lines().collect(Collectors.joining(System.lineSeparator()));}


Be aware, that your code is quite noisy.I know the thread is old, but a lot of people will read it anyway.You could do the same thing using the guava library with:

    if ("POST".equalsIgnoreCase(request.getMethod())) {        test = CharStreams.toString(request.getReader());    }