This is my first time developing a PHP site with JSON and also working with a online database from a Android device, my problem is that I don't know why my script returns null, I haven't send it any variables at all.
My PHP code is:
<?php
$data = file_get_contents('php://input');
$json = json_decode($data, true);
var_dump($json);
?>
The question is: Which is the way to collect the JSON data that the Android Device has send to my php?
If some one asks that is the way I send the data from my Android Device to the php:
In my android app I send the JSON object this way:
HttpResponse response =null;
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpConnectionParams.setSoTimeout(httpClient.getParams(), 5000);
HttpConnectionParams.setConnectionTimeout(httpClient.getParams(),3000);
HttpPost request = new HttpPost(url);
StringEntity se = new StringEntity(json.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json"));
try{
response = httpClient.execute(request);
}catch(SocketException sE)
{
throw sE;
}
The structure of data that I'm sending from my android code is the following one:
JSONObject json = new JSONObject();
try {
json.put("user", 0);
json.put("status", "Confirmed");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
$_POSTurlcontains. As your PHP and Android code seems fine. I have worked upon alike app, so please clarify some more.urliswww.example.com/api.phpapi.php. Now I need to see the structure of data you are sending from your android code.