问题描述
限时送ChatGPT账号..我有一个 API 调用,其中包含以下详细信息
I have an API call with below details
URL:http://pankajservers.in/api/v1/AuthenticateUser 带输入参数下面
URL: http://pankajservers.in/api/v1/AuthenticateUser with Input params below
电子邮件地址和密码
如果我输入错误的凭据,我会收到以下带有状态代码的 JSON 响应:403
if I type wrong credentials, I get below JSON response with Status Code : 403
{"Status":false,"Message":"Invalid Credentials. 5 attempts left.","Data":null}
以下是错误响应代码.
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
if (null != errorworkResponse)
{
Log.d(TAG + ": ", "Error Response code: " + errorworkResponse.statusCode);
}
}
});
有没有办法在这个代码块中获得 JSON 响应?
Is there any way to get JSON response in this code block?
我试过这篇文章:Volley handle onErrorResponse
但它似乎永远不会执行 parseNetworkError
But it seems it never execute parseNetworkError
推荐答案
要在该块上打印错误,您只需要获取响应字节:
To print the Error on that block you just need to obtain the Response bytes:
NetworkResponse networkResponse = errorworkResponse;
if (networkResponse != null && networkResponse.data != null) {
String jsonError = new String(networkResponse.data);
// Print Error!
}
这篇关于如何在 Volley onErrorResponse 中获取 JSON 错误响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论