0

I'm trying to send a push message to parse.com from a Classic ASP based website. Below is my code, and beneath that the PHP equivalent. No error message. (Replaced client data with xxx.) Any suggestions?

ASP code:

<%
Set xmlHttp = Server.CreateObject("Microsoft.XMLHTTP") 
xmlHttp.Open "POST", strUrl, False
xmlHttp.setRequestHeader "X-Parse-Application-Id", "xxx"
xmlHttp.setRequestHeader "X-Parse-REST-API-Key", "xxx"
xmlHttp.setRequestHeader "Content-Type", "application/json"
xmlHttp.Send "{ ""data"": [ { ""channel"": ""xxx"" }, { ""alert"": ""Test Push"" }, { ""sound"": ""push.caf"" } ] }"
set xmlHttp = Nothing 
%>

PHP code:

<?php
$APPLICATION_ID = "xxx";
$REST_API_KEY = "xxx";
$url = 'https://api.parse.com/1/push';
$data = array(
'channel' => 'xxx',
'data' => array(
    'alert' => 'Test Push',
    'sound' => 'push.caf',
),
);
$_data = json_encode($data);
$headers = array(
'X-Parse-Application-Id: ' . $APPLICATION_ID,
'X-Parse-REST-API-Key: ' . $REST_API_KEY,
'Content-Type: application/json',
'Content-Length: ' . strlen($_data),
);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $_data);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_exec($curl);
?>
user692942
  • 16,398
  • 7
  • 76
  • 175
Graham Miles
  • 1
  • 1
  • 6
  • i always find it handy to write out some logging to a text file, and then you can see where your code runs to, and analyse the content of variables – Chris May 09 '14 at 10:50
  • 1
    JSON strings does not equal. Compare string of JSON in the ASP code with output `json_encode($data)` – Kul-Tigin May 09 '14 at 10:59

2 Answers2

1

Looks as though your JSON is not equivalent (as @Kul-Tigin pointed out in the comments).

Looking at your PHP JSON object the Classic ASP should be;

xmlHttp.Send "[ { ""channel"": ""xxx"" }, { ""data"": [ { ""alert"": ""Test Push"" }, { ""sound"": ""push.caf"" } ] } ]"

If you break it down (using your PHP JSON object);

  • $data is an array (containing) []

    • channel is an object { ""channel"": ""xxx"" }

    • data is an array (containing) { ""data"": [] }

      • alert is an object { ""alert"": ""Test Push"" }
      • sound is an object { ""sound"": ""push.caf"" }
Community
  • 1
  • 1
user692942
  • 16,398
  • 7
  • 76
  • 175
0

Assuming this is all your code, the variable strUrl is not set to anything.

Add:

strUrl = "https://api.parse.com/1/push"

As your first line.

silver
  • 650
  • 4
  • 15
  • 1
    Blimey, good spot. Haven't looked at this for a while, but if it's that obvious I'll be administering myself a good kicking. – Graham Miles Apr 11 '16 at 12:30