经典ASP将CURL推送消息发送到parse.com [英] Classic ASP send CURL push message to parse.com

查看:50
本文介绍了经典ASP将CURL推送消息发送到parse.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从基于经典ASP的网站向parse.com发送推送消息.下面是我的代码,在下面是PHP等效代码.没有错误讯息.(将客户数据替换为xxx.)有什么建议吗?

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代码:

<%
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不等效(如 @Kul-Tigin 评论中指出).

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

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

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

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

如果将其分解(使用PHP JSON对象);

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

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

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

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

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

  • alert 是对象 {" alert":" Test Push"}
  • 声音是对象 {"声音":" push.caf"}
  • alert is an object { ""alert"": ""Test Push"" }
  • sound is an object { ""sound"": ""push.caf"" }

这篇关于经典ASP将CURL推送消息发送到parse.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆