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替换为我们原来的.
Replace the redirection handler of xutils yourself
Actual use:
When being redirected to other URLs, we replace the redirected URL with our original one.
Go to https
http has this kind of flaw. If you use https encryption, you can get a self-signed certificate and use it first.
https, although if you directly disable redirection, this problem may appear to be solved, but if your download link itself has a redirection action, you will not be able to download it