如何使用“发送推送通知”;apns到期日“;使用标准C#.NET的头文件?

如何使用“发送推送通知”;apns到期日“;使用标准C#.NET的头文件?,c#,.net,apple-push-notifications,sslstream,C#,.net,Apple Push Notifications,Sslstream,您可以在internet上的许多地方找到类似的代码示例: var apnsHost = "gateway.sandbox.push.apple.com"; var apnsPort = 2195; var timeout = 3000; using(TcpClient client = new TcpClient(AddressFamily.InterNetwork)) { await client.ConnectAsync(apnsHost, apnsPort); usin

您可以在internet上的许多地方找到类似的代码示例:

var apnsHost = "gateway.sandbox.push.apple.com";
var apnsPort = 2195;
var timeout = 3000;

using(TcpClient client = new TcpClient(AddressFamily.InterNetwork))
{
    await client.ConnectAsync(apnsHost, apnsPort);

    using (SslStream sslStream = new SslStream(client.GetStream(), false, _certificateValidationCallback, null))
    {
        try
        {
            sslStream.AuthenticateAsClient(apnsHost, _certificateCollection, System.Security.Authentication.SslProtocols.Tls, true);
        } catch {
            throw;
        }

        MemoryStream memoryStream = new MemoryStream();
        BinaryWriter writer = new BinaryWriter(memoryStream);

        byte[] binaryToken = StringToByteArray(deviceToken);
        writer.Write((byte)0); // The command
        writer.Write((byte)0); // The first byte of the deviceId length (bit-endian first byte)
        writer.Write((byte)32); // The deviceId length (big-endian second byte)
        writer.Write(binaryToken);

        byte[] bytesPayload = Encoding.UTF8.GetBytes(payload);
        writer.Write((byte)0);
        writer.Write((byte)bytesPayload.Length);
        writer.Write(bytesPayload);
        writer.Flush();

        byte[] array = memoryStream.ToArray();
        sslStream.Write(array);
        sslStream.Flush();
    }
}
虽然我知道这段代码与APN握手,建立TLS连接并编写适当的请求内容,但我真的不明白在这段代码中我可以在哪里指定额外的头


Apple描述了各种可以指定的头,我很想指定
apns过期时间
apns优先级
,但我就是想不出在这里可以放在哪里以及什么样的代码来实现我的目标?

我想当TCP客户端连接时(不是connectAsync)您可以指定一个IPEndPoint对象并使用它来设置标题

TCP客户端连接:

IPEndPoint:

我从来没有尝试过发送这样的帖子,所以不确定你的请求的JSON是什么