PHP使用CURL发布八位字节流

时间:2015-11-04 10:46:53

标签: c# php curl windows-phone-8

我尝试在PHP中使用此示例 https://msdn.microsoft.com/library/windows/apps/xaml/hh868252.aspx

在PHP中,这段代码的平等性是什么?

byte[] contentInBytes = Encoding.UTF8.GetBytes(xml);
...
using (Stream requestStream = request.GetRequestStream())
            requestStream.Write(contentInBytes, 0, contentInBytes.Length);

如果我试试这个,这是行不通的

$sendPush = curl_init();
curl_setopt($sendPush, CURLOPT_URL, $uri);  
curl_setopt($sendPush, CURLOPT_HEADER, true);
$headers = array('Content-Type: text/xml',"Content-Type: text/xml","X-WNS-RequestForStatus:true", "X-WNS-Type:wns/toast","Content-Length: " . strlen($toastMessage) ,"X-WindowsPhone-Target: toast","Authorization: Bearer $accessToken");
curl_setopt($sendPush, CURLOPT_HTTPHEADER, $headers);
curl_setopt($sendPush, CURLOPT_RETURNTRANSFER, true);
curl_setopt($sendPush,CURLOPT_POST, true);
curl_setopt($sendPush, CURLOPT_POSTFIELDS, $toastMessage);
$output = curl_exec($sendPush);

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

问题不是来自CURL,而是来自$ toastMessage字符串。 如果要发送WPS通知,则需要使用此处描述的格式之一 https://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx?f=255&MSPPError=-2147217396