(check variablePost)
Well, I want to pass params With volley android this is my current code This is my code with 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");
I want the variable $ _POST ["variablePost"] is passed by volley and then save it to a json to then return it (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 from 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);
This is the result in the logcat
wvolley D/MainActivity: {"dataPerfil":[{"variablePost":null,"nombres":"Carolina"},{"variablePost":null,"nombres":"Ricardo"}]}
The variablePost is null.