2015-11-13 118 views
0

我试图从客户端发送XML到服务器。我使用这个using System.Security.Cryptography.X509Certificates;并得到AuthenticateClient中的异常。唯一的例外是服务器(java)无法从客户端(c#)使用SSL连接接收XML

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火星的Linux操作系统(服务器)

回答

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

如果没有帮助,我没有任何想法:)

+0

谢谢回答。但它不起作用,服务器仍然没有收到XML – Mirza

+0

尝试另一种方法 –

相关问题