-
-
Save sonnyit/08c35464a0f13cbc6bc36e77e418e98e to your computer and use it in GitHub Desktop.
get redirect url from url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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