title: Android Send Post Data To Server
body: <p>This is a possible duplicate of <a href="https://stackoverflow.com/questions/2938502/sending-post-data-in-android">Sending POST data in Android</a></p>
  
  <p>I used this code to send post data to server using android</p>
  
  <pre><code>public void postData() {
          // Create a new HttpClient and Post Header
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost("http://www.mysite.com/android.php");
  
          try {
              // Add your data
              List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);
              nameValuePairs.add(new BasicNameValuePair("id", "12345"));
              nameValuePairs.add(new BasicNameValuePair("stringdata", "Hi"));
              httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  
              // Execute HTTP Post Request
              HttpResponse response = httpclient.execute(httppost);
  
          } catch (ClientProtocolException e) {
              // TODO Auto-generated catch block
          } catch (IOException e) {
              // TODO Auto-generated catch block
          }
      } 
  </code></pre>
  
  <p>But when I run this app it shows this error </p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.senddata/com.example.senddata.MainActivity}: android.os.NetworkOnMainThreadException
  </code></pre>
  
  <p>Whats problem? Can anyone help?</p>