Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在截击中重新登录并重试请求_Android_Android Volley - Fatal编程技术网

Android 在截击中重新登录并重试请求

Android 在截击中重新登录并重试请求,android,android-volley,Android,Android Volley,如果从服务器收到401错误,我需要自动重新登录并重试请求(如果成功)。我在用截击。据我所知,从截击源来看,它在while(true)循环中运行,直到得到响应或异常: @Override public NetworkResponse performRequest(Request<?> request){ while (true) { try { httpResponse = mHttpStack.performRequest(reques

如果从服务器收到401错误,我需要自动重新登录并重试请求(如果成功)。我在用截击。据我所知,从截击源来看,它在while(true)循环中运行,直到得到响应或异常:

@Override
public NetworkResponse performRequest(Request<?> request){
    while (true) {
        try {
            httpResponse = mHttpStack.performRequest(request, headers);
            return httpResponse;
        } catch (IOException e) {
            statusCode = httpResponse.getStatusLine().getStatusCode();
            if (statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_FORBIDDEN) {
                attemptRetryOnException("auth", request, new AuthFailureError(networkResponse));
            }
        }
    }
}
@覆盖
公用网络响应性能请求(请求){
while(true){
试一试{
httpResponse=mHttpStack.performRequest(请求、头);
返回httpResponse;
}捕获(IOE异常){
statusCode=httpResponse.getStatusLine().getStatusCode();
if(statusCode==HttpStatus.SC|u未经授权| | statusCode==HttpStatus.SC|u禁止){
AttemptRetryOneException(“auth”,请求,新的AuthFailureError(networkResponse));
}
}
}
}
但我想停止这个循环,直到获得成功的登录响应,然后继续尝试获得响应


有没有办法在自定义RetryPolicy中执行此操作而不修改凌空源?

实现自己的
RetryPolicy
并覆盖
公共无效重试(凌空错误)
方法如下:

    @Override
    public void retry(VolleyError error) throws VolleyError {
        if (error.networkResponse.statusCode == HttpStatus.SC_UNAUTHORIZED)
        {
            throw new VolleyError("Client is not authorized, retry is pointless");
        }
    }