title: HTTP Post requests using HttpClient take 2 seconds, why?
body: <blockquote><b>Update: </b>
  Found the answer myself, see below :-)</blockquote>
  
  <p>Hi, </p>
  
  <p>I'am currently coding an android app that submits stuff in the background using HTTP Post and AsyncTask. I use the <a href="http://developer.android.com/reference/org/apache/http/client/package-summary.html" rel="noreferrer">org.apache.http.client</a> Package for this. I based my code on <a href="http://www.androidsnippets.org/snippets/36/" rel="noreferrer">this example</a>.</p>
  
  <p>Basically, my code looks like this: </p>
  
  <pre><code>public void postData() {
      // Create a new HttpClient and Post Header
      HttpClient httpclient = new DefaultHttpClient();
      HttpPost httppost = new HttpPost("http://192.168.1.137:8880/form");
  
      try {
          List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);
          nameValuePairs.add(new BasicNameValuePair("id", "12345"));
          nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
          httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  
          // Execute HTTP Post Request
          HttpResponse response = httpclient.execute(httppost);
  
      } catch (ClientProtocolException e) {
       Log.e(TAG,e.toString());
      } catch (IOException e) {
       Log.e(TAG,e.toString());
      }
  }
  </code></pre>
  
  <p>The problem is that the <b>httpclient.execute(..) line takes around 1.5 to 3 seconds</b>, and I do not understand why. Just requesting a page with HTTP Get takes around 80 ms or so, so the problem doesn't seem to be the network latency itself.</p>
  
  <p>The problem doesn't seem to be on the server side either, I have also tried POSTing data to <a href="http://www.disney.com/" rel="noreferrer">http://www.disney.com/</a> with similarly slow results. And Firebug shows 1 ms response time when POSTing data to my server locally.</p>
  
  <p>This happens on the Emulator and with my Nexus One (both with Android 2.2).</p>
  
  <p>If you want to look at the complete code, I've put it on <a href="http://github.com/pableu/http-post-example/blob/master/src/com/gaga/project/newA.java" rel="noreferrer">GitHub</a>.</p>
  
  <p>It's just a dummy program to do HTTP Post in the background using AsyncTask on the push of a button. It's my first Android app, and my first java code for a long time. And incidentially, also my first question on Stackoverflow ;-)</p>
  
  <p>Any ideas why httpclient.execute(httppost) takes so long? </p>