I'm writing an Android app and I want to send some JSON data to a PHP server. The POST request does go to the server but in my server.php script I check the $_POST variable and it is empty. TCP/IP monitor is not in Eclipse ADT and wireshark doesn't show localhost request so I can't see what is actually being sent. So does anyone have an idea what is being sent and how I can access it in PHP? Or have I made a mistake in the code somewhere?
JSONObject json = new JSONObject();
try {
json.put("dog", "cat");
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
HttpURLConnection urlConnection = null;
try {
URL url = new URL("http://10.0.2.2/server.php");
urlConnection = (HttpURLConnection)url.openConnection();
urlConnection.setRequestProperty("Content-Type", "application/json");
urlConnection.setRequestProperty("Accept", "application/json");
urlConnection.setRequestMethod("POST");
urlConnection.setDoOutput(true);
OutputStreamWriter os = new OutputStreamWriter(urlConnection.getOutputStream(), "UTF-8");
os.write(json.toString());
os.close();
}