我正在尝试从客户端向服务器发送XML。我使用此using System.Security.Cryptography.X509Certificates;
并在AuthenticateClient
中调用了Exception。
捕获到AutenticationException,对SSPI的调用失败,请参阅内部 异常。
这是我的代码:
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(服务器)
答案 0 :(得分:0)
尝试添加此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
如果它没有帮助,我不知道:)