您好我正在使用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"
}
]
}
答案 0 :(得分:0)
尝试以下方法: -
因为如果json签名不匹配,它将无法解析。
也看看这个链接...... java.io.IOException : No authentication challenges found
如有任何疑问,请随时回复......