Android用のUrbanairshipプッシュ通知を使用しています。その中で、ブロードキャストを使用してすべてのユーザーに通知を送信したいと思います。それを使用している間、400の悪いリクエストエラーが発生します。
私のコードの何が問題なのか教えてください:
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
こちらで共有してください。
payload
HttpsURLConnectionを使用してこれをサービスに送信する方法。
ありがとう