我正在寻找一种方法来获取抛出的VolleyError的响应代码。我的ErrorListener如下所示:
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());
}
};
我发送给我的VolleyLog的2行打印如下:
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确实知道回来的原因,因为我也可以在我的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.toolbox.BasicNetwork.performRequest(BasicNetwork.java:143)
03-12 10:57:56.902: W/System.err(7147): at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:105)
所以基本上,我想要的是获得响应代码" 403" (禁止)。