본문 바로가기

전산Tip/Java, JSP

자바에서 pushme.to로 푸쉬메세지 보내기 소스

반응형


/*
 * TITLE : pushme.to로 push message 보내기 (http://pushme.to)
 * AUTHOR : grapro.lim@gmail.com 
 * DATE : 2010.10.22
 */
import java.io.*;
import java.net.*;

public class PushMe {

public static void main(String[] args) {
PushMe.push("grapro", "Name", "Message"); 
}

/* push(수신자ID, 보내는이, 메세지) */
public static void push(String id, String name, String msg) {
try {
String query = "message=" + URLEncoder.encode(msg, "UTF-8") + "&signature=" + URLEncoder.encode(name, "UTF-8") + "&nickname=" + URLEncoder.encode(id, "UTF-8");
String u = "http://pushme.to/z/ajax/pushme/?";
System.out.println(u + query);

URL url = new URL(u + query);
URLConnection urlcon = url.openConnection();
HttpURLConnection hurlc = (HttpURLConnection)urlcon;

BufferedReader br = new BufferedReader(new InputStreamReader(hurlc.getInputStream()));

br.close();

} catch(Exception ex){
System.out.println("=== Exception ===");
System.out.println(ex);
}
}

}