on
[안드로이드 Push개발] Fcm https 연결 시 오류(자바1.6 톰캣6.0)
[안드로이드 Push개발] Fcm https 연결 시 오류(자바1.6 톰캣6.0)
String urlStr = "https://fcm.googleapis.com/fcm/send"; String authorization = "key=본인의 서버 키값을 넣으세요"; String token = "받게될 유저의 토큰값을 넣으세요"; String data = "\"data\" : {\r
" + " \"seq\" : \"\",\r
" + " \"title\" : \"제목입니다\",\r
" + " \"message\" : \"내용입니다\"\r
" + " }"; URL url = null; HttpURLConnection connection = null; BufferedOutputStream bos = null; BufferedReader reader = null; try { url = new URL(urlStr); connection = urlStr.startsWith("https://") ? (HttpsURLConnection) url.openConnection(): (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "application/json; charset=utf-8"); connection.setRequestProperty("cache-control", "no-cache"); connection.setRequestProperty("Authorization", authorization); connection.setDoOutput(true); connection.setDoInput(true); connection.connect(); bos = new BufferedOutputStream(connection.getOutputStream()); String message = "{\"to\" : \"" + token + "\"," + data + "," + "\"priority\" :"+ "\"high\"" + "}"; bos.write(message.getBytes("UTF-8")); bos.flush(); bos.close(); int responseCode = connection.getResponseCode(); String responseMessage = connection.getResponseMessage(); StringBuffer buffer = null; if (responseCode == HttpURLConnection.HTTP_OK) { buffer = new StringBuffer(); reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); String temp = null; while ((temp = reader.readLine()) != null) { buffer.append(temp); } reader.close(); } connection.disconnect(); } catch (IOException e) { e.printStackTrace(); }
from http://ehoon.tistory.com/4 by ccl(A) rewrite - 2021-12-02 17:01:20