I'm using Volley to perform rest requests on android. When I make a login attempt it fails to give the response and instead returns an empty response.
The server side works fine, I have received the empty response on Android client side. This is the code I wrote:
HashMap<String, String> params = new HashMap<String, String>();
params.put("email", "[email protected]");
params.put("password", "123456");
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
urlJsonObj, new JSONObject(params), new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
Toast.makeText(getApplicationContext(),
response.toString(),
Toast.LENGTH_LONG).show();
hidepDialog();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
// hide the progress dialog
hidepDialog();
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq);
The correct Answer for this question is shown below. In this version of the request, the Post parameters are overriden in the existing getParams() method of Volley. The mistake I did was to not override that method.