我正在使用适用于Android的Urban飞艇推送通知。在这一点上,我想使用广播发送通知所有我的用户。在使用它时,我得到了400个错误的请求错误。JSON载荷URL发布android
请告诉我,什么是错在我的代码:
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("sixxxxxxw","YSxxxxxxxxxx:Fxxxxxxxxxxxx".toCharArray());
}
});
URL url = new URL("https://go.urbanairship.com/api/airmail/send/broadcast/");
HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type","application/json");
//connection.setRequestProperty("Content-Length", Integer.toString(data.length()));
JSONObject json = new JSONObject();
json.put("title","My title");
json.put("message","My message");
try {
output = connection.getOutputStream();
output.write(json.toString().getBytes());
} finally {
if (output != null) { output.close(); }
}
int status = ((HttpURLConnection) connection).getResponseCode();
System.out.println("status is..." + status);
实际JSON Payload
,我想送的是:
{
"push": {
"aps": {
"alert": "New message!"
}
},
"title": "Message title",
"message": "Your full message here.",
"extra": {
"some_key": "some_value"
}
}
或者此外,如果有sample code for using urban airpship push notifications broadcast api
请分享这里。
如何发送此通过使用HttpsURLConnection服务。
谢谢
不过我得到响应代码400 ... – Udaykiran
我加json.put (“额外”,额外);也在底部仍然是相同的错误 – Udaykiran
你确定你的网址是否正确吗?它应该以类似.../boardcast.json –