I use the following code to get a string representation of the server response. The problem is that it throws an exception in memory when it tries to pass the response toString() . This code works on Android.
String resp = IOUtils.toString(resEntity.getContent(), "UTF-8"); HttpGet httpGet = new HttpGet(url); httpGet.setHeader("Content-Type", "application/json"); httpGet.setHeader("Accept", "JSON"); HttpResponse httpResponse = httpclient.execute(httpGet); HttpEntity resEntity = httpResponse.getEntity(); if (resEntity != null) {
Stacktrace element:
java.lang.OutOfMemoryError: (Heap Size=47395KB, Allocated=36544KB) at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:94) at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:124) at java.lang.StringBuilder.append(StringBuilder.java:271) at org.apache.commons.io.output.StringBuilderWriter.write(SourceFile:138) at org.apache.commons.io.IOUtils.copyLarge(SourceFile:2002) at org.apache.commons.io.IOUtils.copyLarge(SourceFile:1980) at org.apache.commons.io.IOUtils.copy(SourceFile:1957) at org.apache.commons.io.IOUtils.copy(SourceFile:1907) at org.apache.commons.io.IOUtils.toString(SourceFile:778) at org.apache.commons.io.IOUtils.toString(SourceFile:803)
source share