有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

服务器(java)无法从具有SSL连接的客户端(c#)接收XML

我正在尝试将XML从客户端发送到服务器。我使用这个using System.Security.Cryptography.X509Certificates;并在AuthenticateClient中调用了异常。例外是

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。我被困在这里两天了,有人知道这个问题出了什么问题吗

注意:我使用VS2010(客户端)和Eclipse Mars for linux(服务器)


共 (1) 个答案

  1. # 1 楼答案

    尝试添加此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

    如果没用,我也不知道:)