【发布时间】:2017-06-29 23:22:34
【问题描述】:
我正在尝试为服务器中的 Google Firebase 请求 POST。我遵循了文档指南,但没有奏效。
我的发送消息功能是跟随。
private static void sendMsg() throws IOException
{
String url = "https://fcm.googleapis.com/fcm/send";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Authorization", "key=XXXX");
JSONObject msg=new JSONObject();
msg.put("message","test8");
JSONObject parent=new JSONObject();
parent.put("to", "XXXXX");
parent.put("data", msg);
con.setDoOutput(true);
int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + parent.toString());
System.out.println("Response Code : " + responseCode+" "+con.getResponseMessage());
}
响应代码是“411”,消息是“需要长度”。 我也试过设置内容长度,但结果是一样的。
我做错了吗?
【问题讨论】:
标签: java firebase firebase-cloud-messaging