I am using volley library for network calls in Android and jsonObject for sending and getting values from the server.
In my case if I send the correct value, it returns the correct json object, but if I send a wrong input to the server it returns 401 as a request header and response body with error message . But that's not showing in onResponse success method.
here is my code
private void makeLoginReq() {
showProgressDialog();
Map<String, String> postParam = new HashMap<String, String>();
postParam.put("un", user_name.getText().toString());
postParam.put("p", password.getText().toString());
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST,
Server.URL+Server.FUNC_LOGIN, new JSONObject(postParam),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("TAG", response.toString());
hideProgressDialog();
try {
if("0".equalsIgnoreCase(response.getString("status")))
{
startActivity(new Intent(ActivityLogin.this,ActivityHome.class));
}else if("1".equalsIgnoreCase(response.getString("status")))
{
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("TAG", "Error: " + error.networkResponse.statusCode);
hideProgressDialog();
Crouton.makeText(ActivityLogin.this, "Server Error Try again", Style.ALERT).show();
}
}) {
/**
* Passing some request headers
* */
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
headers.put("charset", "utf-8");
return headers;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);
}
My need is to get the json response in public void onResponse(JSONObject response) { method }.
Can anyone help me to overcome this problem?