我正在尝试通过Firebase发送推送通知。我使用以下代码发送数据消息:
IllegalArgumentException: Can't get Kerberos realm
这是我为数据消息编写的Json:
String authKey = <My Server key>;
String FMCurl = "https://fcm.googleapis.com/fcm/send";
URL url = new URL(FMCurl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization", "key=" + authKey);
conn.setRequestProperty("Content-Type", "application/json");
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data.toString());
wr.flush();
wr.close();
int responseCode = conn.getResponseCode();
当它点击{
"data": {
"fromUserId": "346",
"toUserId": "343",
"message": "checkLoginStatus",
"messageId": "1488475905411"
},
"to": "<Firebase Token of the android device>"
}
时,我收到以下错误:
conn.getOutputStream()
我做错了什么?提前谢谢。