Skip to content

Commit b548df9

Browse files
committed
HttpHandler修复某些情况未调用用户自定义跳转的问题
1 parent 21c5880 commit b548df9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

library/src/com/lidroid/xutils/http/HttpHandler.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@
2323
import com.lidroid.xutils.util.core.CompatibleAsyncTask;
2424
import org.apache.http.HttpEntity;
2525
import org.apache.http.HttpResponse;
26+
import org.apache.http.ProtocolException;
2627
import org.apache.http.StatusLine;
2728
import org.apache.http.client.HttpRequestRetryHandler;
29+
import org.apache.http.client.RedirectHandler;
2830
import org.apache.http.client.methods.HttpRequestBase;
2931
import org.apache.http.impl.client.AbstractHttpClient;
3032
import org.apache.http.protocol.HttpContext;
3133

3234
import java.io.File;
3335
import java.io.IOException;
36+
import java.net.URI;
3437
import java.net.UnknownHostException;
3538

3639

@@ -68,6 +71,7 @@ public HttpHandler(AbstractHttpClient client, HttpContext context, String charse
6871
this.context = context;
6972
this.callback = callback;
7073
this.charset = charset;
74+
this.client.setRedirectHandler(notUseApacheRedirectHandler);
7175
}
7276

7377
private State state = State.WAITING;
@@ -339,4 +343,18 @@ public int value() {
339343
return this.value;
340344
}
341345
}
346+
347+
private static final NotUseApacheRedirectHandler notUseApacheRedirectHandler = new NotUseApacheRedirectHandler();
348+
349+
private static final class NotUseApacheRedirectHandler implements RedirectHandler {
350+
@Override
351+
public boolean isRedirectRequested(HttpResponse httpResponse, HttpContext httpContext) {
352+
return false;
353+
}
354+
355+
@Override
356+
public URI getLocationURI(HttpResponse httpResponse, HttpContext httpContext) throws ProtocolException {
357+
return null;
358+
}
359+
}
342360
}

0 commit comments

Comments
 (0)