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'])
params
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);
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);
After spending some more time looking into this problem, I found out that Volley does not properly work with JSON request with POST requests. User @SMR suggested that in the comment section of my question. I also saw a similar answers on Google groups and the mian repo on git. I ended up using GET requests to pass the information to the server and retrieve a JSON feed.