2012-11-07 27 views
11

我想验证HTTP请求中究竟是什么,即参数和标题。我正在调试的代码在执行HTTP请求之前使用MultiPartEntity setEntity。如何打印/记录HTTPRequest正在使用的MultiPartEntity的全部正文内容?

我不是从服务器获取预期的响应,因此要确认什么是被发送到服务器的确切的事情(网址+参数)。

谢谢。

+0

机器人实现无MultiPartEntity支持 – sandrstar

+0

项目使用Apache mime4j库。没有任何问题。 –

回答

7

像下面这样就可以了:

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

由于suhas_sm提到的getContent()方法存在,但没有实现。

+0

这是一个比我之前使用InputStream,BufferedReader和StringBuilder的更优雅的答案,它适用于所有实体类型。谢谢! –

1

我已经通过这个

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);