php - Problems with volley passing parameters -


(check variablepost)

well, want pass params volley android current code code volley

map<string, string> params = new hashmap<string, string>();     params.put("variablepost", "androidvolley");//****         jsonobjectrequest jsonobjreq = new jsonobjectrequest(request.method.post,             url, new jsonobject(params),             new response.listener<jsonobject>() {                  @override                 public void onresponse(jsonobject response) {                     log.d(tag, response.tostring());                     pdialog.hide();                 }             }, new response.errorlistener() {          @override         public void onerrorresponse(volleyerror error) {             volleylog.d(tag, "error: " + error.getmessage());             pdialog.hide();         }     }) {         @override         protected map<string, string> getparams() throws authfailureerror {              map<string, string> params = new hashmap<string, string>();             params.put("variablepost", "androidvolley");             return params;         }         @override         public map<string, string> getheaders() throws authfailureerror {             hashmap<string, string> headers = new hashmap<string, string>();             headers.put("content-type", "application/json; charset=utf-8");             headers.put("user-agent", "my useragent");             return headers;         }         @override         public string getbodycontenttype() {             return "application/json; charset=utf-8";         }      };         jsonobjreq.setretrypolicy(             new defaultretrypolicy(                     defaultretrypolicy.default_timeout_ms, // 2500                     defaultretrypolicy.default_max_retries, // 1                     defaultretrypolicy.default_backoff_mult)); //1f  appcontroller.getinstance().addtorequestqueue(jsonobjreq, "tag_json_obj"); 

want variable $ _post ["variablepost"] passed volley , save json return (for test version)

$db = new db_connect(); $response= array(); $response["dataperfil"]= array();  mysql_query("set names 'utf8'"); $sql = sprintf("select p.nombres, p.apellidos, p.tiposangre, p.email, p.telefono, p.cuentaface, p.cuentatwitt, p.cuentagoogle, p.fondo, p.foto perfil p left join usuario u on p.iduser= u.id"); $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $data_perfil = array(); $data_perfil["nombres"]= $row["nombres"]; $data_perfil["variablepost"] = $_post["variablepost"];//**** $data_perfil["foto"]= $row["foto"];  array_push($response["dataperfil"], $data_perfil); }  $response["success"] = 1; echo json_encode($response); 

result in logcat

wvolley d/mainactivity: {"dataperfil":[{"variablepost":null,"nombres":"carolina"},{"variablepost":null,"nombres":"ricardo"}]} 

variablepost null.

try this:

    stringrequest jsonobjreq = new stringrequest(method.post, url, new response.listener<string>() {          @override         public void onresponse(string response) {             zeputils.log(response);             try {                 jsonobject responsejo = new jsonobject(response);                 //todo responsejo variables             } catch (jsonexception e) {             }         }      }, new response.errorlistener() {          @override         public void onerrorresponse(volleyerror error) {             //todo error();         }      }) {          @override         protected map<string, string> getparams() {             map<string, string> params = new hashmap<string, string>();             params.put("variablepost", "androidvolley");             return params;         }          @override         public map<string, string> getheaders() throws authfailureerror {             hashmap<string, string> headers = new hashmap<string, string>();             headers.put("user-agent", "useragent");             return headers;         }     };      appcontroller.getinstance().addtorequestqueue(jsonobjreq, "tag_json_obj"); 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -