1

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());
        }
}
Mingan Beyleveld
  • 281
  • 2
  • 5
  • 19
  • Are you simply sending Test123? That's not the data you are supposed to send. Have a look at the documentation about how to send pushes using the REST-API https://www.parse.com/docs/push_guide#sending/REST – Björn Kaiser Mar 07 '15 at 20:54
  • Did you solve this issue? I am having close to the same issue. http://stackoverflow.com/questions/31252869/java-passing-parameters-to-parse-com-cloud-code-function-using-rest – JMStudios.jrichardson Jul 06 '15 at 22:03

0 Answers0