Android 低版本 volley 401 错误处理

来源:互联网 发布:php固定资产管理系统 编辑:程序博客网 时间:2024/05/22 09:00

错误提示:

com.android.volley.NoConnectionError: java.io.IOException: No authentication challenges found
我用的三星手机,api 18, 发现无法连接网路,而volley一直报上面的错误。volley 在处理的时候会变成IO错误,并且networkResponse为null,获取不到status code,虽然可以通过其他方法知道是401问题,但很不直接,而且无法返回相应 respone 



下面是我的解决方案,希望能够帮助其他人。有不足,欢迎指教

HurlStack hurlStack = new HurlStack() {            @Override            public HttpResponse performRequest(final Request<?> request, final Map<String, String> additionalHeaders) throws IOException, AuthFailureError {                try {                    return super.performRequest(request, additionalHeaders);                } catch (IOException e) {                    return new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), 401, e.getMessage());                }            }        };Volley.newRequestQueue(context.getApplicationContext(), hurlStack);


0 0
原创粉丝点击