Skip to content

How do I print the content of httprequest request?

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 HttpGet like this:

HttpGet g = new HttpGet();
g.setURI(new URI(""));
g.setHeader("test", "hell yeah");

This is the string representation that I’d like to get:

GET / HTTP/1.1
test: hell yeah

With the post request, I’d also like to get the content string.

What is the easiest way to do it in java for android?


You can print the request type using:


You can print all the headers as mentioned here:

Enumeration<String> headerNames = request.getHeaderNames();
while(headerNames.hasMoreElements()) {
  String headerName = headerNames.nextElement();
  System.out.println("Header Name - " + headerName + ", Value - " + request.getHeader(headerName));

To print all the request params, use this:

Enumeration<String> params = request.getParameterNames(); 
 String paramName = params.nextElement();
 System.out.println("Parameter Name - "+paramName+", Value - "+request.getParameter(paramName));

request is the instance of HttpServletRequest

You can beautify the outputs as you desire.