gpt4 book ai didi

ios - IOS 推送通知中的问题 - 身份验证失败,因为远程方已关闭传输流

转载 作者:可可西里 更新时间:2023-11-01 03:58:57 24 4
gpt4 key购买 nike

我正在使用以下代码进行推送通知。

public void PushNotificationIOS(string message, string registrationKey)
{

string deviceID = registrationKey;
int port = 2195;
String hostname = System.Configuration.ConfigurationManager.AppSettings["HostName"];//"gateway.sandbox.push.apple.com";
string certPath = string.Empty;
certPath = System.Configuration.ConfigurationManager.AppSettings["CertificatePath"] + System.Configuration.ConfigurationManager.AppSettings["Cer
String certificatePath = System.Web.HttpContext.Current.Server.MapPath(certPath);
string certPassword = System.Configuration.ConfigurationManager.AppSettings["CertificatePassword"];
TcpClient client = new TcpClient(hostname, port);
try
{

X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(certificatePath), certPassword);
X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);
SslStream sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
sslStream.AuthenticateAsClient(hostname, certificatesCollection, SslProtocols.Tls, false);
MemoryStream memoryStream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(memoryStream);
writer.Write((byte)0);
writer.Write((byte)0);
writer.Write((byte)32);
writer.Write(StringToByteArray(deviceID.ToUpper()));
String payload = "{\"aps\":{\"alert\":\"" + message + "\",\"badge\":0,\"sound\":\"default\"}}";
writer.Write((byte)0);
writer.Write((byte)payload.Length);
byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload);
writer.Write(b1);
writer.Flush();
byte[] array = memoryStream.ToArray();
sslStream.Write(array);
sslStream.Flush();
client.Close();
}
catch (System.Security.Authentication.AuthenticationException ex)
{

client.Close();
}

}

我收到以下错误身份验证失败,因为远程方已关闭传输流。在 Trace 上,我得到以下内容

System.Net.Security.SslState.CheckThrow(Boolean authSucessCheck)
at System.Net.Security.SslState.get_SecureStream()
at System.Net.Security.SslStream.Write(Byte[] buffer)

我尝试了各种帖子中提到的所有事情,但无法解决问题。

最佳答案

确保证书有效且未损坏。您可以重新生成证书以确保万无一失。

尝试为 SecurityProtocolType 提供所有选项,例如:

sslStream.AuthenticateAsClient(hostname, certificatesCollection, SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls, false);

SecurityProtocolType.Tls12 也可以协商传输层安全 1.1 或更低版本,但请尝试所有选项以确保安全。

enter image description here

有关 SecurityProtocolType 的更多详细信息,请参阅:

https://msdn.microsoft.com/en-us/library/system.net.securityprotocoltype(v=vs.110).aspx

关于ios - IOS 推送通知中的问题 - 身份验证失败,因为远程方已关闭传输流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36739327/

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