Add support for following 301/302 redirects on android
This commit is contained in:
parent
01d43a011a
commit
5d1a201a0c
|
@ -50,6 +50,24 @@ public class Downloader extends AsyncTask<DownloadParams, int[], DownloadResult>
|
||||||
int statusCode = connection.getResponseCode();
|
int statusCode = connection.getResponseCode();
|
||||||
int lengthOfFile = connection.getContentLength();
|
int lengthOfFile = connection.getContentLength();
|
||||||
|
|
||||||
|
boolean isRedirect = (
|
||||||
|
statusCode != HttpURLConnection.HTTP_OK &&
|
||||||
|
(
|
||||||
|
statusCode == HttpURLConnection.HTTP_MOVED_PERM ||
|
||||||
|
statusCode == HttpURLConnection.HTTP_MOVED_TEMP
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isRedirect) {
|
||||||
|
String redirectURL = connection.getHeaderField("Location");
|
||||||
|
connection = (HttpURLConnection) new URL(redirectURL).openConnection();
|
||||||
|
connection.setConnectTimeout(5000);
|
||||||
|
connection.connect();
|
||||||
|
|
||||||
|
statusCode = connection.getResponseCode();
|
||||||
|
lengthOfFile = connection.getContentLength();
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, List<String>> headers = connection.getHeaderFields();
|
Map<String, List<String>> headers = connection.getHeaderFields();
|
||||||
|
|
||||||
Map<String, String> headersFlat = new HashMap<String, String>();
|
Map<String, String> headersFlat = new HashMap<String, String>();
|
||||||
|
|
Loading…
Reference in New Issue