hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shelley, Ryan" <Ryan.Shel...@disney.com>
Subject ResponseBodyAsStream Truncation
Date Fri, 11 Sep 2009 21:44:19 GMT
Hi all... I have, what seems, a pretty basic need, but I'm hitting a
roadblock.  I get a response from an HttpClient/HttpMethod GET request
and when I use "responseBody" I get the full response, but also a
warning that I should be using "responseBodyAsStream".  I changed my
code to use "responseBodyAsStream" and when I look at what I get, it is
always truncated.  Switching back to "responseBody," it once again comes
back complete.  Am I not implementing the stream properly?


int size = 0;

byte[] buffer = new byte[1024];

StringBuffer responseBuff = new StringBuffer();

InputStream in = null;



      in = method.getResponseBodyAsStream();

      while ((size = in.read(buffer)) != -1) 

            responseBuff.append(new String(buffer));





String xmlStr = responseBuff.toString();


When I run the above code and attach my debugger, "xmlStr" is always
truncated when I use "responseBodyAsStream".  As I said, switching back
to "responseBody" works fine and the response is complete.  I've tried
using a byte array and a char array (the reason I use the byte array
here is that the response is saved to a file).


I'm using HttpClient 3.1, and am not currently able to upgrade to 4.0
due to library dependencies.


Thoughts?  Thanks!



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message