【发布时间】:2016-04-11 17:00:07
【问题描述】:
我正在尝试从基于经典 ASP 的网站向 parse.com 发送推送消息。下面是我的代码,下面是 PHP 等效代码。没有错误信息。 (将客户数据替换为 xxx。)有什么建议吗?
ASP 代码:
<%
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 代码:
<?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);
?>
【问题讨论】:
-
我总是觉得写一些日志到文本文件很方便,然后你可以看到你的代码运行到哪里,并分析变量的内容
-
JSON 字符串不相等。比较 ASP 代码中的 JSON 字符串与输出
json_encode($data)
标签: php json curl asp-classic