我正在寻找与以下代码等效的 PHP,即使它不是可编译的代码,只要提供用于执行这些功能的高级函数就很好了。
string subscriptionUri = "sample.com";
HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(subscriptionUri);
sendNotificationRequest.Method = "POST";
sendNotificationRequest.Headers.Add("X-MessageID", "<UUID>");
sendNotificationRequest.ContentType = "text/xml";
sendNotificationRequest.ContentLength = notificationMessage.Length;
byte[] notificationMessage = new byte[] {<payload>};
using (Stream requestStream = sendNotificationRequest.GetRequestStream())
{
requestStream.Write(notificationMessage, 0, notificationMessage.Length);
}
// Sends the notification and gets the response.
HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse();
string notificationStatus = response.Headers["X-NotificationStatus"];
string notificationChannelStatus = response.Headers["X-SubscriptionStatus"];
string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];
所以基本上我正在寻找 PHP 等同于以下内容
- 发送带有一些自定义 header 和内容类型的异步请求并将其发送为异步/流
- 从字符串中创建一个以字节为单位的有效载荷
- 获取响应并查看 header 。
最佳答案
这里有一些功能我认为它会回答你的问题
curl :http://php.net/manual/en/book.curl.php
FSOCKOPEN:http://php.net/manual/en/function.fsockopen.php
文件获取内容:http://php.net/manual/en/function.file-get-contents.php
获取标题:http://php.net/manual/en/function.get-headers.php
关于c# - 异步 HttpWebRequest 上的此 .net/C# 代码的 PHP 等效项、自定义 header 二进制有效负载和分析响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3849113/