title: Android (Java) HTTP POST JSON to server, but the server tells me no POST variables were seen
body: <p>A member of my group project at university created this php for our application.</p>
  
  <pre><code>if ( $_SERVER['REQUEST_METHOD'] != 'POST' ) {
    header( 'HTTP/1.0 405 Method Not Allowed' );
    output( 2, 'only POST is accepted; received ' . $_SERVER['REQUEST_METHOD'], true );
  }
  
  # catch empty POST requests
  if ( count( $_POST ) == 0 ) {
    output( 3,  'no POST variables were sent' );
  }
  </code></pre>
  
  <p>My code passes the first test, but it is always failing this second test. with the error code '3' 'no POST variables were sent'</p>
  
  <p>This is the android code responsible for sending the POST request:</p>
  
  <pre><code>public void uploadToServer(Vector&lt;PointOfInterest&gt; pois)  {
  
          try {
              JSONObject auth = new JSONObject();
              JSONObject walk = new JSONObject();
              JSONArray points = new JSONArray();
  
  
  
  
              walk.put("walk name", "TEST NAME");
              walk.put("walk desc short", "TEST SHORT");
              walk.put("walk desc long", "TEST LONG");
  
  
              for(int i = 0; i &lt; pois.size(); i ++){
  
                  JSONObject location = new JSONObject();
                  location.put("name", pois.get(i).getName());
                  location.put("timestamp", 0);
                  location.put("lattitude",pois.get(i).getLattitude());
                  location.put("longitude",pois.get(i).getLongitude());
                  location.put("Description",pois.get(i).getDescription());
  
                  points.put(location);
  
              }
  
              auth.put("data", walk);
  
              walk.put("locations", points);
  
              auth.put("authorization","");
              auth.put("hash","3b6decebf0bab0e0a08c18a94849d6df1e536d65");
              auth.put("salt", "dave");
  
              UploadASyncTask upload = new UploadASyncTask();
              upload.execute(auth);
  
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
  
  private class UploadASyncTask extends AsyncTask&lt;JSONObject, Void, Void&gt;{
  
          @Override
          protected Void doInBackground(JSONObject...auth) {
              try{
                  HttpClient httpclient = new DefaultHttpClient();
  
                  HttpPost httpPost = new HttpPost("http://project.chippy.ch/upload.php");
  
                  String json = "";
  
                  json = auth.toString();
  
                  StringEntity se = new StringEntity(json);
                  se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
                  httpPost.setEntity(se);
  
                  httpPost.setHeader("User-Agent", "WalkingTourCreator/1.0");
                  httpPost.setHeader("Accept", "application/json");
                  httpPost.setHeader("Content-type", "application/json");
                  //httpPost.setHeader("data", json);
  
                  HttpResponse httpResponse = httpclient.execute(httpPost);
  
                  InputStream inputStream = httpResponse.getEntity().getContent();
                  String result = "";
  
                  if(inputStream != null){
                      result = convertInputStreamToString(inputStream);
  
                  }
                  else{
                      result = "Did not work!";
  
                  }
  
                  Log.d("RESULT", result);
  
  
              }catch(Exception e){
  
                  Log.e("ERROR IN SEVER UPLOAD", e.getMessage());
              }
              return null;
  
  
          }
  </code></pre>
  
  <p>Any ideas, or any obvious problems?</p>
  
  <p>The guy who made the php said this:</p>
  
  <p>"POST needs key-value pairs (as far as I can tell); you'll need to send a key of "data" with the JSON as the contents."</p>
  
  <p>As far as i am aware aren't i doing this?</p>
  
  <p>I have followed a lot of posts on this site and various other bloggs etc, and they all seem to do a similar thing to what i am doing.</p>
  
  <p>Cheers
  Chris.</p>