Hello I am having a lot of issues passing data to my parse.com cloud code function. I am trying to call my cloud code using Parse.com REST services. Below is my code:
private static void pushWithParse() throws IOException
{
String url = "https://api.parse.com/1/functions/testCloudCode";
HttpURLConnection connection = null;
try
{
//Create connection
URL urlRequest = new URL(url);
System.out.println(urlRequest.toString());
connection = (HttpURLConnection)urlRequest.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("X-Parse-Application-Id", "appID");
connection.setRequestProperty("X-Parse-REST-API-Key", "appKey");
connection.setRequestProperty("Content-Type","application/json; charset=UTF-8");
connection.setRequestProperty("Accept-Charset", "UTF-8");
connection.setDoOutput(true);
OutputStream out = connection.getOutputStream();
Writer writer = new OutputStreamWriter(out, "UTF-8");
writer.write("username");
writer.write("=");
writer.write(URLEncoder.encode("joey", "UTF-8"));
InputStreamReader isr = new InputStreamReader(connection.getInputStream(), "UTF-8");
BufferedReader rd = new BufferedReader(isr);
StringBuilder response = new StringBuilder();
String line;
while((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
writer.close();
out.close();
rd.close();
System.out.println(response.toString());
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if(connection != null)
{
connection.disconnect();
}
}
}
I am getting a response from the server with a success. I am trying to print out the username but all I get is this:
Input: {}
Result: Yay need to fix push NOTIFICATIONs
I2015-07-06T17:45:25.223Z]___________________________________________________
I2015-07-06T17:45:25.224Z]No Message provided
I2015-07-06T17:45:25.225Z]No Message provided
for my cloud code:
Parse.Cloud.define("testCloudCode", function(request, response)
{
var parametersPassed = request.params.username;
var requestBody = request.requestBody;
console.log("___________________________________________________");
console.log(requestBody);
console.log(parametersPassed);
console.log("___________________________________________________");
response.success("Yay need to fix push NOTIFICATIONs");
});
I have tried following various posts about passing data in Java but with no luck still getting no message to display. Thank you in advance.