Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to download more than 16144 characters when requesting json from API
    text
    copied!<p>I have an android application which downloads its information as JSON.</p> <p>A typical JSON download is about 2,000-3,000 characters. But i wanted to stress it, so I created a larger file (~48,000 characters). As files go this is still small, under 50kb.</p> <p>The problem I have is when downloading I am only getting 16144 charcters of data. That is <code>reader.readLine()</code> returns just one line containing 16144 characters, as does <code>client.execute(request, new BasicResponseHandler());</code>. Obviously with only part of the file, my JSON parsering code fails quickly as its not a valid JSON object.</p> <p>There are no exceptions raised, so its not an out of memory error. And the problem is repeatable on a HTC desire (2.2) and Galaxy Nexus (4.1.1), so not OS specific either. I've tested the URL in a web browser and it works fine, all the JSON is available so its not a server error.</p> <p><strong>Question</strong> </p> <p>Can anyone point out why it is downloading only 16144 characters, and how to make it download the whole file? </p> <p><strong>Method #1</strong></p> <pre><code>HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(uri); HttpResponse response = client.execute(request); InputStream in = response.getEntity().getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder str = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { str.append(line); } in.close(); result.setJSONResult(str.toString()); </code></pre> <p><strong>Method #2</strong></p> <pre><code>HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(uri); HttpResponse response = client.execute(request); String json = client.execute(request, new BasicResponseHandler()); result.setJSONResult(json); </code></pre> <p>Note - The url is on a LAN network (http://192.168.0.99:8080...), so I've not included it as it won't be useful.</p> <p><strong>Update - Fixed</strong></p> <p>Fixed the problem. In the end I put it down to a file transfer issue rather than memory limits of the phone. Whilst it worked on a PC (Chrome), I found it was broken in other places other than on android such as on the website and other browsers (Safari) didn't work with the raw API call. The underlying problem was the webserver's proxy ngix, wanted to buffer larger responses (over 32kb) however it never had write permissions on the server folders it used for buffering. This meant it sent part of the file, started to buffer and hit a critial error due to been unable to write. When it errored, it stopped sending the rest of the file hence it stopping at an unusual number of bytes. Thanks for all your help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload