【问题标题】:Classic ASP send CURL push message to parse.com经典 ASP 向 parse.com 发送 CURL 推送消息
【发布时间】: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


【解决方案1】:

看起来您的 JSON 不等效(正如 @Kul-Tigincomments 中指出的那样)。

查看您的 PHP JSON 对象,Classic ASP 应该是;

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

如果你分解它(使用你的 PHP JSON 对象);

  • $data 是一个数组(包含[]

    • channel 是一个对象{ ""channel"": ""xxx"" }

    • data 是一个数组(包含{ ""data"": [] }

      • alert 是一个对象 { ""alert"": ""Test Push"" }
      • sound 是一个对象 { ""sound"": ""push.caf"" }

【讨论】:

    【解决方案2】:

    假设这是您的所有代码,变量 strUrl 未设置为任何值。

    添加:

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

    作为你的第一行。

    【讨论】:

    • 天哪,好地方。有一段时间没看这个了,但如果它很明显,我会好好踢自己的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多