I'm trying to POST data to PHP using Android. But getting Null on receiving in PHP. Here is my Code...
Android Code:
try
{
JSONStringer().object()
JSONObject data = new JSONObject();
data.put("phone", "11");
data.put("pwd", "aa");
HttpPost request = new HttpPost("http://www.cslindia.org/viz/test.php");
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
StringEntity entity = new StringEntity(data.toString());
request.setEntity(entity);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
HttpEntity httpEntity =response.getEntity();
String json = EntityUtils.toString(httpEntity);
Log.e("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",json);
}
catch (Exception e)
{
e.printStackTrace();
}
PHP Code:
$json = file_get_content('php://input');
print_r("1".$json); //For Testing Purpose
$jsonObj = json_decode($json, true);
print_r("2".$jsonObj); //For Testing Purpose
$mphone=$jsonObj['phone'];
$mpwd=$jsonObj['pwd'];
But, $json, $jsonObj both have null value. What may be the solution please help me out...