简体   繁体   中英

Classic ASP send CURL push message to parse.com

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);
?>

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"" }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM