I am trying to post JSONObject from android app to php web application using the below code.
String url = "http://10.0.2.2/test/"
URL rest_url = new URL(url);
JSONObject params = new JSONObject();
params.put("username","admin");
// Send POST data request
BufferedReader reader=null;
DataOutputStream printout;
URLConnection conn = rest_url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Accept", "application/json");
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write( params.toString());
wr.close();
When I try to retreive the username in php I am getting null value.
<?php echo $_POST['username'];
?>