短縮URLを展開する

■コード

package hello.java.net;

import java.net.HttpURLConnection;

import java.net.URL;

public class ExpandShortUrl {

public static void main(String[] args) throws Exception {

String urlString = "http://goo.gl/PZwf";

URL url = new URL(urlString);

HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();

System.out.println(httpURLConnection.getURL().toString());

httpURLConnection.getResponseCode();

System.out.println(httpURLConnection.getURL().toString());

httpURLConnection.disconnect();

}

}

■実行結果

http://goo.gl/PZwf

http://www.yahoo.co.jp/

tags

---

Java 短縮URL 展開