I\'ve got a bug involving httprequest, which happens sometimes, so I\'d like to log HttpGet and HttpPost request\'s content when that happens.
So, let\'s say, I create H
Rewrite @Juned Ahsan solution via stream in one line (headers are treated the same way):
public static String printRequest(HttpServletRequest req) {
String params = StreamSupport.stream(
((Iterable) () -> req.getParameterNames().asIterator()).spliterator(), false)
.map(pName -> pName + '=' + req.getParameter(pName))
.collect(Collectors.joining("&"));
return req.getRequestURI() + '?' + params;
}
See also how to convert an iterator to a stream solution.