【发布时间】:2019-03-15 15:35:48
【问题描述】:
您可以在互联网上的许多地方找到类似的代码示例:
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();
}
}
虽然我知道这段代码与 APNS 握手、建立 TLS 连接并编写适当的请求内容,但我真的不明白在这段代码中我可以在哪里指定额外的标头!
Apple 描述了 here 可以指定的各种标头,我对指定 apns-expiration 和 apns-priority 很感兴趣,但我只是不知道我可以在哪里以及在这里使用哪种代码来实现我的目标?
【问题讨论】:
标签: c# .net apple-push-notifications sslstream