Android HttpResponse - Content has been consumed
android, httpresponse
Solution
Is this in the emulator or on your phone? It could be an emulator specific problem. I've test it on my device, and it works perfectly.
Do you perhaps have a debugger watch that could be consuming the content?
Problem
The method below falls over when reading the HttpResponse with the error: "Content has been consumed". I understand that the content can only be consumed once but I get this error on the very first attempt and I don't see anywhere in the code where I'm possibly consuming it twice. ``` private static String getData(String url, HttpParams params) { StringBuilder builder = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); if (params != null) { httpGet.setParams(params); } String result = ""; try { HttpResponse response = client.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { builder.append(line); } content.close(); result = builder.toString(); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return result; } ```