Skip to content

Instantly share code, notes, and snippets.

@TomTasche
Created July 25, 2011 14:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TomTasche/1104272 to your computer and use it in GitHub Desktop.
Save TomTasche/1104272 to your computer and use it in GitHub Desktop.
How To: Expand a shortened URL in Java
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