我正在尝试从客户端向服务器发送 XML。我使用此 using System.Security.Cryptography.X509Certificates;
并在 AuthenticateClient
中调用了异常。异常(exception)是
AutenticationException was caught, A call to SSPI failed, see inner exception.
这是我的代码:
public static SslStream OpenSSL(string _IP, int _port)
{
try
{
TcpClient client = new TcpClient(_IP, _port);
// Create a secure stream
SslStream sslStream = new SslStream(client.GetStream(), false,
new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
if (sslStream != null)
{
sslStream.AuthenticateAsClient(_IP);
}
return sslStream;
}
catch (Exception _e)
{
Util.Log.Track(Config.System.LogMode.UTIL, "Comms.Handler.OpenSSL: exception = " + _e.ToString());
return null;
}
}
我可以连接到服务器,但服务器不会接收 XML。我被困在这里 2 天了,有人知道这个问题出了什么问题吗?
注意:我使用 VS2010(客户端)和 Eclipse Mars for linux(服务器)
最佳答案
尝试添加此 C# 代码
System.Net.ServicePointManager.ServerCertificateValidationCallback =
((sender, certificate, chain, sslPolicyErrors) => true);
它忽略了 ssl 验证的错误
然后尝试另一种方法 改变它
if (sslStream != null)
{
sslStream.AuthenticateAsClient(_IP);
}
对此
X509Certificates.X509Certificate2Collection xc = new X509Certificates.X509Certificate2Collection();
sslStream.AuthenticateAsClient(_IP, xc, Security.Authentication.SslProtocols.Tls, false);
实际上,我不确定 SslProtocols 标志。也许 SslProtocols.Tls | SslProtocols.Ssl3
如果没有帮助,我不知道:)
关于java - 服务器(java)无法使用 SSL 连接从客户端(c#)接收 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33689035/