title: Apache httppost Android webservice return large number of XML takes times so long
body: <p>i'm using apache httppost to get XML data from ASP.NET webservice in server.</p>
  
  <p>When the number of xml records is below thousands (e.g. 400 xml) the process time is quite fast about 10 seconds, but when the number of records are thousands (e.g. 4000 xml) the process time is about like 20 minutes which is crazy.</p>
  
  <p>It supposed to be 100 seconds ((4000/400) * 10) = a.k.a 1 minute and 40 seconds</p>
  
  <p>I'm trying to split my query using limit and offset and place the httppost execute inside loop, but it still takes the same time </p>
  
  <pre><code>httpParameters = new BasicHttpParams();
  httpParameters.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
  HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
  HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);       
  HttpConnectionParams.setTcpNoDelay(httpParameters, true);
  
  
  httpclient = new DefaultHttpClient(httpParameters);     
  httppost = new HttpPost("http://myipaddress/servicename.asmx/" + wsFunctionName);       
  httppost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
  List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
  for (int i = 0 ; i &lt; paramname.length; i ++){
      nameValuePairs.add(new BasicNameValuePair(paramname[i], para[i]));
  }
  httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));           
  httpresponse = httpclient.execute(httppost);
  HttpEntity entity = httpresponse.getEntity();
  contentlen = (int) entity.getContentLength();               
  InputStream is = entity.getContent();
  BufferedReader rd = new BufferedReader(new InputStreamReader(is));
  
  String line = "";
  try {
      while ((line = rd.readLine()) != null) {
          result += line;
          progressvalue += line.length();
          prog = (int) ((progressvalue * 100) / contentlen );
          publishProgress(new Integer[]{prog, in+1});
      }   
  } catch (Exception e) {
      Log.e("e", e.toString());
  } finally {
      is.close();
      entity.consumeContent();
  }
  </code></pre>
  
  <p>Note: Previously I didn't use the </p>
  
  <p><code>httpParameters.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);</code> </p>
  
  <p>and </p>
  
  <p><code>httppost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);</code> </p>
  
  <p>code but the process time takes so long (no difference)</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The problem is not the connection, but the number of lines from XML return is so huge so the readLine process keep going until the line end.</p>
  
  <p>I've change my XML return from List of Strings[] (which has so many line break) to string. previously its takes about 20 minutes, now its only 5 seconds because just need read one line.</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>Test result are really amazing,</p>
  
  <p>Using conventional string += "string" takes 14 seconds, using StringBuilder it only takes 2 second.</p>
  
  <p>Thanks greenapps</p>