0

Hi I am using volley to parse my api, when i pass the valid credentials it works fine gives me ab auth token and if the credentials are wrong i still want it to parse the response but its giving me "No authentication challenges found" and JSONObject response as null response in return. Is it something with volley or it is something with the php script??

private void sendRequest_getAuth(){
        try {
            JSONObject jsonBody = new JSONObject();
            jsonBody.put("phone", "phn in numeric");
            jsonBody.put("password", "pswd");
            JsonObjectRequest JSONRequest = new JsonObjectRequest(Request.Method.POST, "the api url", jsonBody,
                    new com.android.volley.Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject response) {
                            jresponse=response;
                            show_getAuth(jresponse);
                        }
                    },
                    new com.android.volley.Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Log.d("onError_response",jresponse.toString());
                            Toast.makeText(LoginActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
                         show_getAuth(jresponse);
                        }
                    });

            RequestQueue requestQueue = Volley.newRequestQueue(this);
            requestQueue.add(JSONRequest);
        }

required Response which should be parsed:-

{
  "errors": [
    {
      "message": "Invalid Credentials"
    }
  ]
}
Sebastian
  • 417
  • 3
  • 13
tech office
  • 65
  • 1
  • 8

1 Answers1

0

Try the following thing:-

  • Check you Url in Postman (or any applicaiton) and pass invalid credentials and check what response you are receiving from webservice. If you are not getting respose as you have mentioned in you question then its Server side issue (PHP).
  • Now if you are getting response as above, the kindly check if successfull login and error in login response pattern is same.

Because if the json signature mismatches it won't be able to parse.

  • If its entering in Error callback kindly mention what is the error server is returning.

Have look at this link too... java.io.IOException : No authentication challenges found

In case of any doubts, feel free to reply...

Community
  • 1
  • 1
Mrinmoy
  • 1,370
  • 2
  • 18
  • 28
  • The message comes from the api but i dont know what to do nest i am trying to get the status code but getting null, repose in postman is the same as required response. – tech office Jan 06 '17 at 06:26
  • new com.android.volley.Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { NetworkResponse ns=error.networkResponse; Log.d("onError_response", ns.statusCode+""); Toast.makeText(LoginActivity.this, ns.toString(), Toast.LENGTH_LONG).show(); Log.d("onError_response", jresponse.toString()); //show_getAuth(jresponse); } – tech office Jan 06 '17 at 06:26
  • Have you checked the link I have provided... If its working on postman, then the issue is in android code, you need to match the config details with server side like header and request type, etc, – Mrinmoy Jan 06 '17 at 06:30