哪个库或内置功能可以让你像bitly,fb.me,google's shortener等那样获取一个简短的URL ...并在最快的时间内得到它的最终链接?
谢谢
大多数编程时间,我现在正在使用来自apache的httpclient,想知道它们是否是内置的替代品
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)