MultiThreadDownload
MultiThreadDownload copied to clipboard
UnSupported response code:302
- I have issue when downloading the avatar from facebook : http://graph.facebook.com/207171792967664/picture?width=300&height=300
with errorMessage: UnSupported response code:302.
- The code 302 is Move temporary means it will redirect to another link: https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpa1/v/t1.0-1/c0.0.219.219/11215742_102608163424028_530138717734899392_n.jpg?.....
And how to resolve it? Thanks a lot!
Can workaround by using codes below to get redirect link.
public static String getRedirectLink(String url) {
String result = url;
try {
URL obj = new URL(url);
HttpURLConnection conn = (HttpURLConnection) obj.openConnection();
conn.setReadTimeout(5000);
System.out.println("Request URL ... " + url);
boolean redirect = false;
// normally, 3xx is redirect
int status = conn.getResponseCode();
if (status != HttpURLConnection.HTTP_OK) {
if (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM
|| status == HttpURLConnection.HTTP_SEE_OTHER)
redirect = true;
}
System.out.println("Response Code ... " + status);
if (redirect) {
// get redirect url from "location" header field
String newUrl = conn.getHeaderField("Location");
System.out.println("Redirect to URL : " + newUrl);
result = newUrl;
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
unfortunately this is not work for me, for example i can't download this image from net, for example:
https://kermany.com/wp-content/uploads/2016/03/dr-1.jpg