我的 pop3 客户端有问题。我无法在 utf-8 或 iso 8859-1 中编码我从 tcpclient 流中检索到的电子邮件。这是代码:
TcpClient tcpClient = new TcpClient();
txtLog.Text = "Dico:\r\nConnect me to " + txtServer.Text + ":" + txtPort.Text + "\r\n\r\n";
tcpClient.Connect(txtServer.Text, Convert.ToInt32(txtPort.Text));
NetworkStream netStream = tcpClient.GetStream();
System.Text.Encoding iso_8859_1 = System.Text.Encoding.GetEncoding("iso-8859-1");
System.IO.StreamReader strReader = new System.IO.StreamReader(netStream, iso_8859_1);
System.Text.Encoding utf_8 = System.Text.Encoding.UTF8;
if (tcpClient.Connected)
{
txtLog.Text = "Il server risponde:\r\n" + strReader.ReadLine() + "\r\n\r\n";
byte[] WriteBuffer = new byte[100990024];
ASCIIEncoding enc = new System.Text.ASCIIEncoding();
WriteBuffer = enc.GetBytes("USER " + txtUser.Text + "\r\n");
txtLog.Text = "Dico:\r\nHere's the username: " + txtUser.Text + "\r\n\r\n";
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
txtLog.Text = "Il server risponde\r\n" + strReader.ReadLine() + "\r\n\r\n";
WriteBuffer = enc.GetBytes("PASS " + txtPass.Text + "\r\n");
txtLog.Text = "Dico:\r\nHere's the password: " + txtPass.Text + "\r\n\r\n";
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
txtLog.Text = "Il server risponde\r\n" + strReader.ReadLine() + "\r\n\r\n";
WriteBuffer = enc.GetBytes("RETR " + messaggio.Text + "\r\n");
txtLog.Text = "Messaggio: " + messaggio.Text + "\r\n\r\n";
string message;
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
while (true)
{
message = strReader.ReadLine();
if (message == ".")
{
if (message == "/n") break;
break;
}
else
{
txtLog.Text += message + "\r\n\r\n";
continue;
}
}
我总是得到这样的东西“questa_=E8_una_prova_=F2_=EC_?=”。怎么了?谢谢你。