I'm new in android I try to send POST method to PHP using JSON the data I sent do not appear in PHP, In PHP the request released but when I try to read the POST data I have array null.
protected void sendJson(final String username, final String password) {
Thread t = new Thread() {
public void run() {
Looper.prepare();
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);
HttpResponse response;
JSONObject json = new JSONObject();
String URL = "MY_URL";
try {
HttpPost post = new HttpPost(URL);
json.put("section", "API");
json.put("username", username);
json.put("password", password);
StringEntity se = new StringEntity( json.toString());
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
post.setEntity(se);
response = client.execute(post);
if(response!=null)
{
String result = EntityUtils.toString(response.getEntity());
Toast.makeText(getBaseContext(), result, Toast.LENGTH_LONG).show();
//InputStream in = response.getEntity().getContent(); //Get the data in the entity
}
} catch(Exception e) {
e.printStackTrace();
Toast.makeText(getBaseContext(), "Cannot Estabilish Connection", Toast.LENGTH_LONG).show();
}
Looper.loop();
}
};
t.start();
}