I am trying to POST a value to a script running on a local server. My code is given below :
final String data = "poet=nazmul";
//Toast.makeText(getApplicationContext(), "ok", Toast.LENGTH_LONG).show();
StringRequest request = new StringRequest(Request.Method.POST, "http://192.168.1.112:8080/api/post.php?" + data, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Toast.makeText(getApplicationContext(), volleyError.toString(), Toast.LENGTH_LONG).show();
}
});
AppController.getInstance().addToRequestQueue(request);
But the local server does not respond. My php code is:
<?php
$poet = $_POST['poet'];
echo json_encode(array('poet'=>$poet));
?>
When I open the URL directly in a web browser, I get this error:
Notice: Undefined index: poet in C:\xampp\htdocs\api\post.php on line 2 {"poet":null}
How can I solve this problem? The main problem was windows firewall, it was preventing me from connecting to the local server, after disabling it and changing the php code $_POST to $_GET everything seems working fine.Thanks everyone for their help.