How can I print/log entire body contents of MultiPartEntity that is being used by HTTPRequest?

suhas_sm picture suhas_sm · Nov 7, 2012 · Viewed 7.5k times · Source

I want to verify what exactly is in HTTP request i.e Parameters and Headers. The code, which I am debugging uses MultiPartEntity to setEntity before making executing HTTP Request.

response = executePost(multipartEntity);
statusCode = response.statusCode;

I am not getting the expected response from the server hence want to verify what is the exact thing (url + parameters) that is being send to the server.

Thanks.

Answer

Mark Doyle picture Mark Doyle · May 16, 2013

Something like the following will do the trick:

ByteArrayOutputStream bytes = new ByteArrayOutputStream();
multipartEntity.writeTo(bytes);
String content = bytes.toString();

As suhas_sm mentioned the getContent() method exists but is not implemented.