I have an HTTP Post request which is supposed to return about 80k of data. My server is on EC2 and when I run the curl request from an EC2 instance things work fine.
curl --data '<request data>' <my server address>
However, when I use my machine at home, I get the following:
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed
100 36128 0 35880 100 248 20775 143 0:00:01 0:00:01 --:--:-- 20775
curl: (18) transfer closed with outstanding read data remaining
I get a similar issue where only around 37KB is read when I use the following code:
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Content-type", "application/json");
StringEntity entity = new StringEntity(params.toString());
httpPost.setEntity(entity);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
Log.d("MyServer", "json len: " + json.length());
Any idea what I am doing wrong? I am very confused by the fact that things work fine for curl when I use an EC2 machine to send the request. Is this some sort of timeout issue?