Created
July 25, 2011 14:40
-
-
Save TomTasche/1104272 to your computer and use it in GitHub Desktop.
How To: Expand a shortened URL in Java
This file contains 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
import java.io.IOException; | |
import java.net.HttpURLConnection; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
/** | |
* http://blog.tomtasche.at/2011/07/how-to-expand-shortened-url-in-java.html | |
* | |
* @author Thomas Taschauer | |
* | |
*/ | |
public class URLExpander { | |
public static String expand(String url) { | |
try { | |
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); | |
connection.setInstanceFollowRedirects(true); | |
connection.getInputStream().read(); | |
} catch (MalformedURLException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment