String param = ""; param = "registration_id="+registration_id; param += "&collapse_key="+collapse_key; param += "&data.identity="+collapse_key; param += "&data.mdn="+"0100000000"; param += "&data.payload="+data_payload; param += "&data.time="+String.valueOf(System.currentTimeMillis()); param += "&delay_while_idle="+delay_while_idle; System.out.println("param : " + param) ; byte[] postData = param.getBytes("UTF-8"); try { String rtnValue = ""; URL url = new URL("http://android.apis.google.com/c2dm/send"); HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection(); urlConnection.setRequestMethod("POST"); urlConnection.setDoOutput(true); urlConnection.setUseCaches(false); urlConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); urlConnection.setRequestProperty("Content-Length", Integer.toString(param.length())); urlConnection.setRequestProperty("Authorization", "GoogleLogin auth="+auth); OutputStream os = urlConnection.getOutputStream(); os.write(postData); os.close(); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); System.out.println("responseCode : " + responseCode); if(responseCode == HttpURLConnection.HTTP_OK) { InputStream inputStream = urlConnection.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); String readLine; while ((readLine = reader.readLine()) != null) { System.out.println(readLine); } reader.close(); } urlConnection.disconnect(); }catch(Exception e) { System.out.println(e.toString()); } }
'Programming > 과거포스팅' 카테고리의 다른 글
자바스크립트 파일 업로드 이미지 미리보기(javaScript file upload img preview) (23) | 2012.07.26 |
---|---|
java unzip (0) | 2012.05.03 |
C2DM 연동 AUTH값 받아오기 (4) | 2012.04.23 |
No subject alternative DNS name matching android.apis.google.com found. (0) | 2012.04.23 |
HTML 다운로드 태그 + jsp 스트림출력 (4) | 2012.04.12 |