6
我試圖通過傳遞服務器IP,SslProtocols.Tls
和X509Certificate2Collection
使用SslStream.AuthenticateAsClient
方法從C#發送APN。但我收到錯誤消息:APN由於「驗證失敗,因爲遠程方已關閉傳輸流」
Authentication failed because remote party has closed the transport stream
我試圖在這裏討論,但沒有工作的每一個解決方案。請在下面幫忙是
X509Certificate2Collection certs = new X509Certificate2Collection();
X509Certificate2 xcert = new X509Certificate2();
xcert.Import(@"D:\certify.p12", "password", X509KeyStorageFlags.UserKeySet);
certs.Add(xcert);
// Apple development server address
string apsHost;
if (xcert.ToString().Contains(ProductionKeyFriendName))
apsHost = "gateway.push.apple.com";
else
apsHost = "gateway.sandbox.push.apple.com";
// Create a TCP socket connection to the Apple server on port 2195
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(apsHost, 2195);
// Create a new SSL stream over the connection
sslStream = new SslStream(tcpClient.GetStream());
// Authenticate using the Apple cert
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
sslStream.AuthenticateAsClient(apsHost, certs, System.Security.Authentication.SslProtocols.Tls, false);
return true;
Apple是否頒發了客戶端證書? – jww
你有這個工作嗎?我試圖在這裏做完全相同的事情,具有完全相同的錯誤;) –