I am trying to check if cardinals user provided are valid using get
request with Authentication
header. To be honest I have not tried success scenario, however when I pass not valid cardinals I get 401 error from server as supposed. However Volley
do not handle this error as it suppose to do.
My request:
StringRequest loginRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>()
{
@Override
public void onResponse(String response) {
valid[0] = 1;
Log.d("Response", response);
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
valid[0] = 2;
Log.d("ERROR","error => "+error.toString());
}
}
) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
String usernamepwd = u+":"+p;
params.put("Authentication", Base64.encodeToString(usernamepwd.getBytes(), Base64.DEFAULT));
return params;
}
};
after executing the code I get:
03-02 08:43:32.088 4119-4150/com.example E/Volley: [209] BasicNetwork.performRequest: Unexpected response code 401 for https://example.com/api/checklogin
Overrided function onErrorResponse
is not called. What Can I do to properly handle HTTP
errors?