gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 16:51:25 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com