Skip to content

Instantly share code, notes, and snippets.

@sonnyit
Forked from kanzmrsw/getRedirectUrl.java
Created September 30, 2022 12:24
Show Gist options
  • Select an option

  • Save sonnyit/08c35464a0f13cbc6bc36e77e418e98e to your computer and use it in GitHub Desktop.

Select an option

Save sonnyit/08c35464a0f13cbc6bc36e77e418e98e to your computer and use it in GitHub Desktop.
get redirect url from url
public class Test extends Activity {
...
public String getRedirectUrl(String url) {
URL urlTmp = null;
String redUrl = null;
HttpURLConnection connection = null;
try {
urlTmp = new URL(url);
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
try {
connection = (HttpURLConnection) urlTmp.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
try {
connection.getResponseCode();
} catch (IOException e) {
e.printStackTrace();
}
redUrl = connection.getURL().toString();
connection.disconnect();
return redUrl;
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment