我收到以下错误“调用sspi失败后看到内部异常。收到的消息是意外的或在Windows 7中格式错误”。我尝试了所有可能的方法,但没有运气。请检查
这是代码
int port = 2195;
String deviceID = "d6c597fcc4e3426993cf29a3a8857efbed3462d5d8e9e32c0f8b387djkdklldk";
String hostname = "gateway.sandbox.push.apple.com"; // TEST
//String hostname = "gateway.push.apple.com"; // REAL
string p12FilePassword = "password";
// @"cert.p12";
String certificatePath = HttpContext.Current.Server.MapPath("~/Certificate.p12");
X509Certificate2 clientCertificate = string.IsNullOrEmpty(p12FilePassword) ? new X509Certificate2(File.ReadAllBytes(certificatePath)) : new X509Certificate2(File.ReadAllBytes(certificatePath), p12FilePassword, X509KeyStorageFlags.MachineKeySet);
X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);
TcpClient client = new TcpClient(hostname, port);
SslStream sslStream = new SslStream(client.GetStream(), false, ValidateServerCertificate, SelectLocalCertificate);
try
{
sslStream.AuthenticateAsClient(hostname, certificatesCollection, System.Security.Authentication.SslProtocols.Tls, false);
}
catch (Exception e)
{
throw (e);
//client.Close();
//return;
}
答案 0 :(得分:0)
我看到这是一个老帖子,但我最近遇到了这个问题。应用程序可以在我的Windows10上运行,在Windows Server 2008r2和2012r2上失败。 解决方案是摆脱SslStream并使用openssl或bouncycastle等库来进行连接。