我尝试连接到SSL TCP服务器,它可以在我的浏览器上运行,我可以收到硬编码的响应。在应用程序中,使用ReadLine函数时会出现异常。
错误:System.ArgumentException:无法读取流 System.IO.StreamReader..ctor(Stream stream,Encoding encoding,Boolean detectEncodingFromByteOrderMarks,Int32 bufferSize,Boolean leaveOpen) 在System.IO.StreamReader..ctor(Stream stream)上 App_Name.Program.Connection.Connect(String serverIp,Int32 serverPort, ConnectionInfo connectionInfo)
tcpClient = new TcpClient(serverIp, serverPort);
sslStream = new SslStream(tcpClient.GetStream(), false, new RemoteCertificateValidationCallback(TrustAllCertificatesCallback));
streamReader = new StreamReader(sslStream);
streamWriter = new StreamWriter(sslStream);
string inputLine;
while ((inputLine = streamReader.ReadLine()) != null)
{
ParseMessage(streamWriter, serverIp, inputLine);
}
答案 0 :(得分:1)
此行必须添加到连接功能下方才能正确初始化。
sslStream.AuthenticateAsClient(serverIp);