1

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?

wislo
  • 1,110
  • 2
  • 13
  • 24
  • 1
    Check [this](http://stackoverflow.com/questions/1759956/curl-error-18-transfer-closed-with-outstanding-read-data-remaining) and [this](http://serverfault.com/questions/598650/nginx-terminates-connection-after-65k-bytes) – TJ- Feb 16 '15 at 05:40
  • @TJ- Thanks for the links. Issue was the I didnt have proxy_temp_path set in nginx. After setting that, things are working well. – wislo Feb 16 '15 at 12:34

1 Answers1

0

The issue turned out to be with my nginx setup. I had not specified proxy_temp_path and as the request was large, it was having issues storing the request to be forwarded. http://wiki.nginx.org/HttpProxyModule#proxy_temp_path

wislo
  • 1,110
  • 2
  • 13
  • 24