Hello guyz,
I think this code will help you when you develop an application in API 23 or above...
Any Queries just fill the form on the right side of my blog and click send....
try {
URL url1=new URL(url);
JSONObject j = new JSONObject();
j.put("tag", "login");
j.put("username", "admin");
j.put("password", "admin");
HttpURLConnection connection=null;
connection=(HttpURLConnection)url1.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setConnectTimeout(30000);
connection.setReadTimeout(25000);
OutputStreamWriter wr=new OutputStreamWriter(connection.getOutputStream(),"UTF-8");
wr.write(j.toString());
wr.flush();
wr.close();
Log.d("Json in json.java", j.toString());
is=connection.getInputStream();
Log.d("is in json.java",is.toString());
}catch (Exception e){
e.printStackTrace();
}
In PHP file receive Values as JSON Object...
$json = file_get_contents('php://input');
$obj = json_decode($json);
$tag=$obj->{'tag'};
$username=$obj->{'username'};
$password=$obj->{'password'};
No comments:
Post a Comment