Using a buffer to convert http request responses to string in Android - Not getting entire response
I'm developing an app that posts to a site and I'm trying to store the entity response as a string. However, the string only seems to contain a small portion of the response, roughly 35 lines or so. I'm wondering if it has something to do with buffer overflow but really I am not sure. My code is below:
static String getResponseBody(HttpResponse r开发者_如何学JAVAesponse) throws IllegalStateException, IOException{
String content = null;
HttpEntity entity = response.getEntity();
if (entity != null)
{
InputStream is = entity.getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = br.readLine()) != null)
{
if(isBlankString(line) == false)
{
sb.append(line + "\n");
}
}
br.close();
content = sb.toString();
}
return content;
isBlankString just notes if a line doesn't contain any characters, as there's alot of blank lines in the response that were bugging me. I have the issue of not getting the whole response with or without this. Any body know what's going on or how to fix this?
Thanks
In my application I use just single line to get response string from entity:
final String responseText = EntityUtils.toString(response.getEntity());
精彩评论