我有一个托管在 azure 中的数据服务,我从该服务向 iphone 发送通知,但在与 apns 建立连接时出现以下错误
“对 SSPI 的调用失败。收到的消息是意外的或格式错误。”我还参考了以下链接来解决相同的错误,但仍然收到错误
苹果通过 APNS Sharp 推送通知 https://stackoverflow.com/questions/3162076/apple-push-notification-with-apns-sharp/3221612#3221612 and
C# iPhone 推送服务器? https://stackoverflow.com/questions/1056083/c-iphone-push-server
try
{
using (TcpClient client = new TcpClient())
{
try
{
client.Connect("gateway.sandbox.push.apple.com", 2195);
Logging("TSSLProDi :Connected to Apple");
}
catch (Exception ex)
{
Logging("TSSLProDi :" + ex.Message + "-IE-" + ex.InnerException);
}
using (NetworkStream networkStream = client.GetStream())
{
Logging("TSSLProDi :Client connected.");
X509Certificate clientCertificate = new X509Certificate(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"startup\certname.pfx"), "mycertpassword");
X509CertificateCollection clientCertificateCollection = new X509CertificateCollection(new X509Certificate[1] { clientCertificate });
// Create an SSL stream that will close the client's stream.
SslStream sslStream = new SslStream(
client.GetStream(),
false,
new RemoteCertificateValidationCallback(validateServerCertificate),
null
);
try
{
sslStream.AuthenticateAsClient("gateway.sandbox.push.apple.com", clientCertificateCollection, System.Security.Authentication.SslProtocols.Default, false);
Logging("TSSLProDi :slStreamAuthenticated");
}
catch (AuthenticationException ex)
{
Logging("TSSLProDi :" + "Exception: " + ex.Message.ToString());
if (ex.InnerException != null)
{
Logging("Inner exception: " + ex.InnerException.Message.ToString());
}
Logging("TSSLProDi :" + "Authentication failed - closing the connection.");
client.Close();
return;
}
}
}
}
catch (Exception ex)
{
Logging("TSSLProCert :" + ex.Message + "-IE-" + ex.InnerException);
}
我也在虚拟机上安装了所需的证书。我从苹果获得的 iPhone 开发者身份证书上收到的一个警告是“Windows 没有足够的信息来验证此证书”我的 iPhone 证书有问题吗?请帮助我,我被困住了
得到解决方案我刚刚将 X509Certificate 更改为 X509Certificate2 并将 X509CertificateCollection 更改为 X509Certificate2Collection
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)