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","可惡,但是已經(jīng)阻止了重定向!"); 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替換為我們原來的.