我试图使用PHP +卷曲是相当于例子中提到的文件“SendToast.aspx.cs”HTTP POST请求与PHP +卷曲
我的PHP文件看起来像下面这样here创建HTTP POST请求,
<?php
$uri = $_POST["uri"];
$title = $_POST["title"];
$subtitle = $_POST["subtitle"];
$file = 'file.txt';
//phpinfo();
$theData = '<?xml version="1.0" encoding="utf-8"?>\\r';
$theData .= "<wp:Notification xmlns:wp=\"WPNotification\">";
$theData .= "<wp:Toast>";
$theData .= "<wp:Text1>" .$title;
$theData .= "</wp:Text1>";
$theData .= "<wp:Text2>" .$subtitle;
$theData .= "</wp:Text2>";
$theData .= "<wp:Param>/Page2.xaml?NavigatedFrom=Toast Notification</wp:Param>";
$theData .= "</wp:Toast>";
$theData .= "</wp:Notification>";
$header_array = array('X-WindowsPhone-Target' => 'toast','X-NotificationClass' => '2','Content-type:' => 'text/xml','Content-length:' => strlen($theData));
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER,$header_array);
curl_setopt($ch, CURLOPT_URL,$uri);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$theData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//print_r($ch);
$server_output = curl_exec ($ch);
//echo $server_outout;
//curl_close ($ch);
if (curl_errno($ch))
{
print "Error: " . curl_error($ch);
}
else
{
// Show me the result
print $server_output;
curl_close($ch);
}
//file_put_contents($file, $theData);
?>
谁能告诉我什么即时做错了什么?我还试图用HttpRequest类来创建这个例子,但我很难配置php_http.dll延伸,似乎该文件具有依赖关系或其损坏。尽管如此,帮助这一个将是伟大的。
请让我们知道您遇到的错误或不正确的行为。 –
对不起哥们,但我不太熟悉php的输出函数,我可以告诉的是,如果一切正常,它应该发送通知给我的手机应用程序(ASP示例完美工作,它发送通知,意味着phoneapp可以接收),server_output变量不会返回任何内容,其空白或可能是我不知道如何完全打印它,你能提示我如何打印错误代码或响应数据?这将是非常有用的 – maxchirag
你忘了网址编码POST数据:curl_setopt($ ch,CURLOPT_POSTFIELDS,urlencode($ theData)); – hindmost