title: problem POSTing android JSONObject to PHP
body: <p>I am having trouble getting an android POST of a simple JSONObject to show up in the $_POST data on the server.  The server is PHP 5.3.4 and the android side is an SDK 8 emulator.  I can post a simple NameValuePair as normal and it shows up but when I switch to the JSONObject + StringEntity that you see below the $_POST array shows { }.  Go ahead and run the code below against my test php page.  It has a var_dump of $_POST and $_SERVER as well as searching for one of the expected keys ('email').  You will see I have tried numerous 'ContentType's to see if that was the problem.  I've even used WireShark to verify that the TCP conversation looks good between client and server.  The POST data is in there but it isn't showing up in the server's vars.  I am stuck... thanks for any help you can offer.</p>
  
  <pre><code>import java.io.InputStream;
  
  import org.apache.http.HttpResponse;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.entity.StringEntity;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.params.HttpConnectionParams;
  import org.json.JSONObject;
  
  import android.util.Log;
  
  public class TestPOST {
      protected static void sendJson (final String email, final String pwd) {
          HttpClient client = new DefaultHttpClient();
          HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
          HttpResponse response;
          String URL = "http://web-billings.com/testPost.php";
          try{
              HttpPost post = new HttpPost(URL);
  
              // NameValuePair That is working fine...
              //List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);  
              //nameValuePairs.add(new BasicNameValuePair("email", email));  
              //nameValuePairs.add(new BasicNameValuePair("password", pwd));  
              //post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
              //Log.i("main", "P2DB - String entity 'se' = "+nameValuePairs.toString());
  
              JSONObject jObject = new JSONObject();
              jObject.put("email", email);
              jObject.put("password", pwd);
              StringEntity se = new StringEntity(jObject.toString());
              //se.setContentType("charset=UTF-8");
              se.setContentType("application/json;charset=UTF-8");
              //se.setContentType("application/json");
              //se.setContentType("application/x-www-form-urlencoded");
  
              post.setEntity(se);
              Log.i("main", "TestPOST - String entity 'se' = "+GetInvoices.convertStreamToString(se.getContent()));
  
              response = client.execute(post);  
  
              /*Checking response */
              if(response!=null){
                  InputStream in = response.getEntity().getContent(); //Get the data in the entity
                  String message = GetInvoices.convertStreamToString(in);
                  Log.i("main", "P2DB - Connect response = "+message);
              }
          }
          catch(Exception e){
              e.printStackTrace();
              //createDialog("Error", "Cannot Establish Connection");
          }
      }
  }
  </code></pre>
  
  <p>Here is the testPost.php page if you like:</p>
  
  <pre><code>&lt;?php
      echo "\r\n&lt;pre&gt;\r\n";
      var_dump("\$_POST = ", $_POST)."\r\n";
      echo '$_POST[\'email\'] = '.$_POST['email']."\r\n";
      var_dump("\$_SERVER = ", $_SERVER)."\r\n";
      echo '&lt;/pre&gt;';
      die; 
  ?&gt;  
  </code></pre>