简体   繁体   中英

PHP post octet stream with CURL

I try to follow this sample in PHP https://msdn.microsoft.com/library/windows/apps/xaml/hh868252.aspx

What will be the equivalent of this peace of code in PHP?

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

If i try this, this is not working

$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);

Thanks for your help

The problem wasn't from CURL but from the $toastMessage string. If you want to send WPS notifications, you need to use one of the format describe here https://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx?f=255&MSPPError=-2147217396

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM