您可以在互联网上的许多地方找到类似的代码示例:
before:
A--B--C <-- master
after:
A--B--C--F--G <-- master
/
D--E
虽然我知道该代码与APNS握手,建立TLS连接并写入适当的请求内容,但我真的不明白在该代码中我可以在哪里指定其他标头!
Apple描述了here可以指定的各种标头,我很想指定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-expiration
,但我只是想不出我可以在哪里和哪种类型的代码适合这里实现我的目标吗?
答案 0 :(得分:0)
我认为当您具有TCP客户端连接(而不是connectAsync)时,您可以指定IPEndPoint对象并使用它来设置标头。
IPEndPoint:https://docs.microsoft.com/en-us/dotnet/api/system.net.ipendpoint?view=netframework-4.7.2
我从未尝试过发送这样的帖子,所以不确定您的请求的JSON是什么。