I have the code below (Volley Library By Google) to send a POST request to my php server and get information as a result. I tried the code without checking isset($_POST['id'])
in php and the code worked fine. Buy when I started to check, php will skip the if statement and go to else meaning the code is not sending the params
correctly. How can I fix this?
RequestQueue queue = Volley.newRequestQueue(Chat.this);
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
CHAT_URL_FEED, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("THISSSSSSSS", response.toString());
if (response != null) {
parseChatJsonFeed(response);
}
}
}, new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error){
VolleyLog.d("Here", "Error: " + error.getMessage());
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("id", id);
return params;
}
};
queue.add(jsonObjReq);
I also tried the following code:
RequestQueue queue = Volley.newRequestQueue(Chat.this);
JSONObject params = new JSONObject();
try {
params.put("id", id);
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
CHAT_URL_FEED, params,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("THISSSSSSSS", response.toString());
if (response != null) {
parseChatJsonFeed(response);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("Here", "Error: " + error.getMessage());
}
});
queue.add(jsonObjReq);
but I still get the same result.
I tried the code without checking isset($_POST['id']) in php and the code worked fine.
can you post that, i think$_POST['id']
isnull
in either cases. – Pertif(isset($_POST['id']) && !empty($_POST['id']) && $_POST['id'] != null){//mycode here}
– Aerostation@mmlooloo
because i do not get notified. – Pert