android - How to send POST request to local server PHP script using Volley? -
i trying post value script running on local server. code 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 local server not respond. php code is:
<?php $poet = $_post['poet']; echo json_encode(array('poet'=>$poet)); ?>
when open url directly in web browser, error:
notice: undefined index: poet in c:\xampp\htdocs\api\post.php on line 2 {"poet":null}
how can solve problem?
you're doing request because of concatenation of ? , + data. if change server script $_post $_get , change request.method.post request.method.get work.
Comments
Post a Comment