在Java中解析缩短的目标URL链接的最快方法是什么?

Jam*_*mes 1 java

哪个库或内置功能可以让你像bitly,fb.me,google's shortener等那样获取一个简短的URL ...并在最快的时间内得到它的最终链接?

谢谢

Bal*_*usC 7

大多数编程时间,我现在正在使用来自apache的httpclient,想知道它们是否是内置的替代品

java.net.URLConnection.

String location = "http://tinyurl.com/so-hints";
HttpURLConnection connection = (HttpURLConnection) new URL(location).openConnection();
connection.setInstanceFollowRedirects(false);
while (connection.getResponseCode() / 100 == 3) {
    location = connection.getHeaderField("location");
    connection = (HttpURLConnection) new URL(location).openConnection();
}
System.out.println(location); // http://msmvps.com/blogs/jon_skeet/archive/2010/08/29/writing-the-perfect-question.aspx
Run Code Online (Sandbox Code Playgroud)