c# - 无法读取流 (sslStream)

标签 c# ssl

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

Error: System.ArgumentException: Cannot read the stream on System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen) on System.IO.StreamReader..ctor(Stream stream) on 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);
}

最佳答案

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

sslStream.AuthenticateAsClient(serverIp);

关于c# - 无法读取流 (sslStream),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32789780/

相关文章:

c# POP3客户端实现

c# - 如何将参数传递给exe?

ssl - 使用 des3 生成私钥卡住了

python - 请求无法连接到 TLS 服务器

c# - 如何使用activeMQ NMS和C#实现同步请求-响应应用程序?

c# - 找出值类似于列表中的任何值

c# - 无平台网络的预处理器符号

python - 由于 AKI DirName 扩展 : Python [SSL: CERTIFICATE_VERIFY_FAILED] . 在 openSSL 中找到根本原因 ..:无法获取本地颁发者证书

java - 打开连接失败 : javax.net.ssl.SSLException : Unrecognized SSL message, 明文连接?

ssl - 在 HP Nonstop 上为 MQ 队列管理器启用 SSL