日期:2014-05-17 浏览次数:21427 次
public class SslTcpClient
{
private static Hashtable certificateErrors = new Hashtable();
//下面的方法调用由RemoteCertificateValidationDelegate。
public static bool ValidateServerCertificate(object sender,X509Certificate certificate,X509Chain chain,SslPolicyErrors sslPolicyErrors)
{
////此处报错 根据验证过程,远程证书无效。也就是这个地方了
if (sslPolicyErrors == SslPolicyErrors.None)
return true;
//Console.WriteLine("Certificate error证书错误: {0}", sslPolicyErrors);
return false;
}
public static void RunClient(string machineName, string serverName)
{
//创建一个TCP / IP客户端套接字
TcpClient client = new TcpClient(machineName, 9090);
//Console.WriteLine("Client connected.");
//创建一个SSL流,将关闭客户端的流
SslStream sslStream = new SslStream(
client.GetStream(),
false,
new RemoteCertificateValidationCallback(ValidateServerCertificate),