There are plenty of URL shortening services designed for Twitter. Recently, Twitter picked bit.ly as their official URL shortening service. Here is quick Java code to expand short URL to original URL-
System.out.println(”Short URL: “+ shortURL);
urlConn = connectURL(shortURL);
urlConn.getHeaderFields();
System.out.println(”Original URL: “+ urlConn.getURL());
// connectURL - This function will take a valid url and return a URL object representing the url address.
URLConnection connectURL(String strURL) {
URLConnection conn =null;
try {
URL inputURL = new URL(strURL);
conn = inputURL.openConnection();
int test = 0;
}catch(MalformedURLException e) {
System.out.println(”Please input a valid URL”);
}catch(IOException ioe) {
System.out.println(”Can not connect to the URL”);
}
return conn;
}
| website design quote |