bit.ly 를 사용하려면 먼저 회원가입을 하고 login id랑 apikey를 발급 받아야 함.
url 생성은 한달에 5,000개까지 가능함.
String url = "http://api.bit.ly/v3/shorten";
String changeUrl = "http://seongsland.tistory.com";
String param = "login=[YOURID]&apiKey=[YOURKEY]&format=txt&uri=" + changeUrl;
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setDoInput(true);
OutputStream os = con.getOutputStream();
os.write(param.getBytes());
os.flush();
os.close();
if(con.getResponseCode() < 400) {
InputStream is = con.getInputStream();
byte[] read = new byte[1024];
while(is.read(read, 0, 1024) > -1) {
System.out.println(new String(read));
}
is.close();
}
con.disconnect();
'Java' 카테고리의 다른 글
RSA 암호화 java 구현 class (0) | 2018.02.23 |
---|---|
goo.gl api java 구현 (0) | 2016.10.06 |
Object와 Object[]에 대한 내용 (1) | 2011.11.10 |
base64, DES chiper - encode, decode 구현 (6) | 2011.10.11 |
jdbc로 procedure call sample (2) | 2011.08.05 |