php - Send data (POST or GET) to server with Volley Lib in Android -


i've developed application i'm going send data phone server json, use volley library in android.
can not send data server!

my simple php code :

$name = $_get["name"]; $j = array('name' =>$name); echo json_encode($j); 

my java code :

    private void makejsonobjectrequest() {         mrequestqueue = volley.newrequestqueue(this);         string url = "http://my-site-name/sampleget.php";          stringrequest jsonobjreq = new stringrequest(             request.method.get,              url,             new response.listener<string>() {                 @override                 public void onresponse(string response) {                     log.d("result:", response);                     toast.maketext(getapplicationcontext(), response, toast.length_short).show();                 }             },              new response.errorlistener() {                 @override                 public void onerrorresponse(volleyerror error) {                     volleylog.d("err", "error: " + error.getmessage());                     makejsonobjectrequest();                 }             }         ){             @override             protected map<string, string> getparams() {                 map<string, string> params = new hashmap<>();                 params.put("name", "json");                 return params;             }         };         mrequestqueue.add(jsonobjreq);     } 

it got link below : click see link

but still not use , send data (post or get) mobile server!!!
how can this?

as advised on how send json android php?

from current code, remove method:

        @override         protected map<string, string> getparams() {             map<string, string> params = new hashmap<>();             params.put("name", "json");             return params;         } 

and override getbody() method instead. then, adapt return json data need request body based on below sample:

    public byte[] getbody() throws authfailureerror {         jsonobject js = new jsonobject();         try {                js.put("fieldname", "fieldvalue");         } catch (jsonexception e) {                e.printstacktrace();         }          return js.tostring().getbytes();     } 

and in php decode json data:

    $jsonrequest = json_decode(stream_get_contents(stdin));     var_dump($jsonrequest); 

please let me know if more information needed.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -