0
그래서이 질문은 Jersey을 사용하여 보았습니다. 하지만 여전히 내 서버에서 주제 구독 사용자에게 간단한 푸시 알림을 보내는 방법을 파악하지 못했습니다. 을 기반으로 구축하려고하므로 내 요청에 무엇이 잘못되었는지 이해하지 못합니다.Firebase가 서버 알림을 전송합니다.
public class OverSLANotifier {
public static void main(String[] args) throws Exception, FirebaseException {
String rawData = "{\"to\": \"/topics/sla\",\"data\": {\"message\": \"This is test push notification!\",}}";
String encodedData = URLEncoder.encode(rawData, "UTF-8");
URL u = new URL("https://fcm.googleapis.com/fcm/send");
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization", "key=AI<redacted>VGB6YwPWrinoz1YFBgdKv4Pgm8s");
conn.setRequestProperty("Content-Type", "application/json");
OutputStream os = conn.getOutputStream();
os.write(encodedData.getBytes());
System.out.println(""+ conn.getResponseCode() + "-->>"+conn.getResponseMessage());
}
내 클라이언트는 properly set 내가 콘솔에서 보내는 경우받을 수 있습니다.
응답은 항상 :
401 - >> 무단