我試圖使用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