gpt4 book ai didi

ssl - APNS 抛出错误 "A call to SSPI failed, see inner exception. - The message received was unexpected or badly formatted"

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

我收到此异常“对 SSPI 的调用失败,请参阅内部异常”,内部异常为“收到的消息意外或格式错误”

尝试调用此方法时:

sslStream.AuthenticateAsClient(apsHost, certs, System.Security.Authentication.SslProtocols.Tls, false);

我正在使用生产证书并在端口 2195 调用生产 APNS 服务器(“gateway.push.apple.com”)。

我知道有几篇关于此的帖子(大多数都是旧的),但我确实尝试了在其他帖子中找到的所有内容以及在 google 上进行的不同搜索,但没有任何方法可以解决我的问题。

我找到的大部分答案都是将 SSL 协议(protocol)从 Ssl3 更改为 Tls,所以我这样做了,但没有奏效。

还尝试使用 xcode 从 apple 重新创建推送服务证书,并重新安装它。

如果有人知道我还遗漏了什么,我将不胜感激

这是剩下的代码:

private void PushIosNotification(object notificationData)
{
Log.Get().Info(Log.BuildMessageEx(notificationData));
SslStream sslStream = null;
TcpClient tcpClient = null;
MemoryStream ms = null;
BinaryWriter bw = null;
try
{
NotificationData nData = (NotificationData)notificationData;
X509Certificate2Collection certs = new X509Certificate2Collection();
if (certs != null)
{
certs.Add(getServerCert(nData.AppleProductionPushCertificateFriendlyName, nData.AppleDevelopmentPushCertificateFriendlyName, nData.IsProduction));

string apsHost = certs[0].ToString().Contains("Production") ? nData.AppleServerURL : nData.AppleSandBoxServerURL;


tcpClient = new TcpClient(apsHost, int.Parse(nData.AppleServerPort));

sslStream = new SslStream(tcpClient.GetStream());

sslStream.AuthenticateAsClient(apsHost, certs, System.Security.Authentication.SslProtocols.Tls, false);

byte[] buf = new byte[256];

ms = new MemoryStream();
bw = new BinaryWriter(ms, Encoding.UTF8);

bw.Write(new byte[] { 0, 0, 32 });
bw.Write(hexToData(nData.DeviceId));
bw.Write((byte)0);

// Create the APNS payload - new.caf is an audio file saved in the application bundle on the device
string msg = "{\"aps\":{\"alert\":\"" + nData.Message.Replace("₪", "₪").Replace("ש\"ח", "₪") + "\",\"badge\":" + nData.IBadge + ",\"sound\":\"new.caf\",\"url\":\"www.google.com\"}}";

UTF8Encoding encoding = new UTF8Encoding();
byte[] postBytes = encoding.GetBytes(msg);

// Write the data out to the stream
bw.Write((byte)postBytes.Length);
bw.Write(postBytes);
bw.Flush();

sslStream.Write(ms.ToArray());
}
}
catch (System.Security.Cryptography.CryptographicException CrEx)
{
Log.Get().Error("CryptographicException ConnectToAPNS1:", CrEx);
}
catch (Exception e)
{
Log.Get().Error("PushIosNotification", e);
}
finally
{
if (tcpClient != null)
{
tcpClient.Close();
}
if (sslStream != null)
{
sslStream.Close();
}
if (ms != null)
{
ms.Close();
}
if (bw != null)
{
bw.Close();
}
}
}

谢谢,

最佳答案

好的,现在它可以工作了,除了用相同的代码创建一个控制台应用程序之外什么也没做,它在那里工作,然后原始代码也开始工作..

关于ssl - APNS 抛出错误 "A call to SSPI failed, see inner exception. - The message received was unexpected or badly formatted",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44128842/

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