c# - 异步 HttpWebRequest 上的此 .net/C# 代码的 PHP 等效项、自定义 header 二进制有效负载和分析响应

标签 c# php .net wcf

我正在寻找与以下代码等效的 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 等同于以下内容

  1. 发送带有一些自定义 header 和内容类型的异步请求并将其发送为异步/流
  2. 从字符串中创建一个以字节为单位的有效载荷
  3. 获取响应并查看 header 。

最佳答案

关于c# - 异步 HttpWebRequest 上的此 .net/C# 代码的 PHP 等效项、自定义 header 二进制有效负载和分析响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3849113/

相关文章:

c# - 标签页添加用户控件

c# - 测试 SQL 连接字符串可用性的最有效方法

c# - 如何用 "and"替换最后一个逗号

c# - 在 Click 事件中从 TextBox 中选择文本

php - 如何获取按钮以在 jQuery 确认对话框上执行操作?

c# - 如何使用异步调用检查 Web 服务是否可用

c# - 我应该从 SQL CLR 函数中使用 EF6

c# - Linq - 获取根后代

php - 对 Mysql 数组进行切片

java - 使用 JSON (GSON) 将 PHP 关联数组传输到 Java Map<String, Double>