I am trying to send a push notification to android users from within my desktop java program. I am using parse.com's REST API to do so. I am getting an exception as follows:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Server returned HTTP response code: 400 for URL: https://api.parse.com/1/push
Here is my code below:
public void sendPushToParse() {
String line;
StringBuffer jsonString = new StringBuffer();
try {
URL url = new URL("https://api.parse.com/1/push");
String payload="Test123";
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
//connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("X-Parse-Application-Id", "myAppID");
connection.setRequestProperty("X-Parse-REST-API-Key", "myKey");
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
writer.write(payload);
writer.close();
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((line = br.readLine()) != null) {
jsonString.append(line);
}
br.close();
connection.disconnect();
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}