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.

suhas_sm
  • 2,064
  • 1
  • 18
  • 23

2 Answers2

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.

Mark Doyle
  • 4,804
  • 3
  • 20
  • 23
  • This was a MUCH more elegant answer than my previous attempts with InputStream, BufferedReader and StringBuilder, and it works for all Entity types. Thanks! – steve-gregory Sep 26 '14 at 23:44
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);
shailesh
  • 1,783
  • 2
  • 17
  • 26