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

2

12

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.

Spann answered 7/11, 2012 at 7:18 Comment(2)
android has no MultiPartEntity supportChequer
Project uses Apache mime4j library. No issues whatsover.Spann
C
7

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.

Cracy answered 16/5, 2013 at 12:46 Comment(1)
This was a MUCH more elegant answer than my previous attempts with InputStream, BufferedReader and StringBuilder, and it works for all Entity types. Thanks!Valuator
P
1

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);
Pantelleria answered 11/6, 2014 at 6:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.