https://support.qiniu.com/hc/...
七牛提供的解决方法,但是项目中应用次方法局限性太大.
遂问还有其他的解决方法吗?
//自己解决了
自己替换掉xutils的重定向handler
public class NoHttpRedirectHandler implements HttpRedirectHandler {
private String url;
public NoHttpRedirectHandler(String url) {
this.url=url;
}
public HttpRequestBase getDirectRequest(HttpResponse response) {
if(response.containsHeader("Location")) {
HttpGet request = new HttpGet(url);
MGLog.e("upgrade","可恶,但是已经阻止了重定向!");
if(response.containsHeader("Set-Cookie")) {
String cookie = response.getFirstHeader("Set-Cookie").getValue();
request.addHeader("Cookie", cookie);
}
return request;
} else {
return null;
}
}
}
实际使用:
HttpManagerX.getHttpUtils().configHttpRedirectHandler(new NoHttpRedirectHandler(url)).download(url, target, true, new
RequestCallBack<File>(){...}
当被重定向到其他的url时,我们把重定向的url替换为我们原来的.
阿神2017-04-17 17:50:40
自己替换掉xutils的重定向handler
public class NoHttpRedirectHandler implements HttpRedirectHandler {
private String url;
public NoHttpRedirectHandler(String url) {
this.url=url;
}
public HttpRequestBase getDirectRequest(HttpResponse response) {
if(response.containsHeader("Location")) {
HttpGet request = new HttpGet(url);
MGLog.e("upgrade","可恶,但是已经阻止了重定向!");
if(response.containsHeader("Set-Cookie")) {
String cookie = response.getFirstHeader("Set-Cookie").getValue();
request.addHeader("Cookie", cookie);
}
return request;
} else {
return null;
}
}
}
实际使用:
HttpManagerX.getHttpUtils().configHttpRedirectHandler(new NoHttpRedirectHandler(url)).download(url, target, true, new
RequestCallBack<File>(){...}
当被重定向到其他的url时,我们把重定向的url替换为我们原来的.