Java – how do I get the response code from volleyerror?

I'm looking for a way to get the response code of the volleyerror thrown My errorlistener looks like this:

Response.ErrorListener errorListener = new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        error.printStackTrace();
        //Get response code here
        VolleyLog.e("Error: ",error.toString());
        VolleyLog.e("Error: ",error.getLocalizedMessage());
    }
};

The 2 lines I sent to my volleylog are printed as follows:

03-12 10:57:56.932: E/Volley(7147): [1] 1.onErrorResponse: Error: 
03-12 10:57:56.932: E/Volley(7147): [1] 1.onErrorResponse: Error:

Volley does know that he is back, because I can also see the following in my volleylog:

03-12 10:57:56.692: E/Volley(7147): [41854] BasicNetwork.performRequest: Unexpected response code 403 for https://*******/Employee/authenticate
03-12 10:57:56.897: E/Volley(7147): [41854] BasicNetwork.performRequest: Unexpected response code 403 for https://*******/Employee/authenticate
03-12 10:57:56.902: W/System.err(7147): com.android.volley.AuthFailureError
03-12 10:57:56.902: W/System.err(7147):     at com.android.volley.tool@R_567_2419@.BasicNetwork.performRequest(BasicNetwork.java:143)
03-12 10:57:56.902: W/System.err(7147):     at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:105)

So basically, what I want is to get this response code "403" (Forbidden)

Solution

Through volleyerror:

error.networkResponse.statusCode

Looking at the source code, I can see that volleyerror has a public final member called networkresponse, which saves the statuscode of the HTTP call You should check NPE

Here you can find the source code of networkresponse Here you can find the source code of volleyerror

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>