title: Sending POST data from Android application to PHP script
body: <p>I'm trying to send some POST data to a PHP script from an android application. How should the PHP script look like? This is what I tried but it doesn't work;</p>
  
  <p>Android code:</p>
  
  <pre><code>class SendPostReqAsyncTask extends AsyncTask&lt;String, Void, String&gt; {
      @Override
      protected String doInBackground(String... params) {
  
          // Create a new HttpClient and Post Header
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost("http://www.alex26.0fees.net/script.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", "AndDev is Cool!"));
              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
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(String result) {
  
      }
  }
  </code></pre>
  
  <p>PHP script:</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['id']))
      echo $_POST['id'];
  if(isset($_POST['stringdata']))
      echo $_POST['stringdata'];
  ?&gt;
  </code></pre>