如何从 TcpClient 读取响应代码

How to read response code from TcpClient

我只是想知道如何从 TCP 客户端读取响应代码?示例代码如下。

var tcpClient = new TcpClient();
tcpClient.Connect(this.Settings.MailServer,  this.Settings.MailServerPort);


NetworkStream stream = tcpClient.GetStream();

你可以使用这个:

byte[] message = new byte[512];
int bytesRead;
bytesRead = stream.Read(message, 0, message.Length);
ASCIIEncoding encoder = new ASCIIEncoding();
Console.WriteLine(encoder.GetString(message, 0, bytesRead));

流 > 字节 > 字符串

byte[] buffer = new byte[1024];
int bytesRead = stream.Read(buffer, 0, buffer.Length);
response = Encoding.ASCII.GetString(buffer, 0, bytesRead);
Console.WriteLine(response);