无法读取流(sslStream)

本文关键字:sslStream 读取 | 更新日期: 2023-09-27 18:14:37

我正在尝试连接到SSL TCP服务器,它在我的浏览器上运行,我可以接收硬编码的响应。在应用程序上,使用ReadLine函数时会出现异常。

错误:系统。ArgumentException:无法读取上的流系统IO.StreamReader.ctor(流,编码,布尔detectEncodingFromByteOrderMarks,Int32缓冲区大小,布尔leaveOpen(在系统上。上的IO.StreamReader.ctor(流(应用程序名称。程序联系Connect(字符串服务器IP、Int32服务器端口、,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);
}

无法读取流(sslStream)

必须在Connect函数下方添加此行,才能正确初始化握手。

sslStream.AuthenticateAsClient(serverIp);