Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 224
suhas_sm Avatar asked Nov 07 '12 07:11

suhas_sm


2 Answers

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.

like image 61
Mark Doyle Avatar answered Nov 01 '22 10:11

Mark Doyle


I have achieved by this

MultipartEntity reqEntityB = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream(
                (int) reqEntityB.getContentLength());
        reqEntityB.writeTo(out);
        String entityContentAsString = new String(out.toByteArray());
        Log.e("multipartEntitty:", "" + entityContentAsString);
like image 37
shailesh Avatar answered Nov 01 '22 10:11

shailesh