没有发现身份验证挑战 - Volley

时间:2017-01-06 05:37:54

标签: android json parsing android-studio parse-platform

您好我正在使用volley来解析我的api,当我传递有效凭据时,它工作正常给我认证令牌,如果凭据错误,我仍然希望它解析响应,但它给了我“没有发现身份验证质询“而JSONObject响应为null响应。它是凌空的东西还是php脚本的东西?

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);
        }

必须解析的响应: -

{
  "errors": [
    {
      "message": "Invalid Credentials"
    }
  ]
}

1 个答案:

答案 0 :(得分:0)

尝试以下方法: -

  • 检查Postman(或任何应用程序)中的Url并传递无效凭据并检查您从webservice收到的回复。如果你没有像你在问题中提到的那样得到respose那么它的服务器端问题(PHP)。
  • 现在,如果您收到上述回复,请检查登录响应模式是否成功登录和错误。

因为如果json签名不匹配,它将无法解析。

  • 如果输入错误回调,请提及错误服务器返回的内容。

也看看这个链接...... java.io.IOException : No authentication challenges found

如有任何疑问,请随时回复......