我正在为自己的lib工作pop3,因为我没有在这里建议的那些找到我需要的东西。我的问题是,当打开一条消息时它只能读取某一行(通常是文本中的一个链接)并且它会停止,循环但不会崩溃。代码是:
Data = "RETR 1" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
txtLog.Text += RdStrm.ReadLine() + CRLF;
for (int i = 0; i < 33; i++)
{
txtLog.Text += RdStrm.ReadLine() + CRLF;
}
string szTemp;
szTemp = RdStrm.ReadLine();
// here it's supposed to start reading the actual message
while(szTemp != "-")
{
txtLog.Text += szTemp + CRLF;
szTemp = RdStrm.ReadLine();
}
答案 0 :(得分:1)
Match reg1 = Regex.Match(ifOk, "OK(.*)", RegexOptions.IgnoreCase);
if (reg1.Success)
{
txtLog.Text += "Ready To Start!\r\n";
Data = "USER XXXX" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
txtLog.Text += RdStrm.ReadLine() + CRLF;
Data = "PASS XXXX" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
txtLog.Text += RdStrm.ReadLine() + CRLF;
Data = "STAT" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
txtLog.Text += RdStrm.ReadLine() + CRLF + CRLF + CRLF + CRLF + CRLF;
Data = "RETR 1" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
txtLog.Text += RdStrm.ReadLine() + CRLF;
string szTemp;
szTemp = RdStrm.ReadLine();
// POP3 uses . as the end of a message
while(szTemp != ".")
{
txtLog.Text += szTemp + CRLF;
szTemp = RdStrm.ReadLine();
}
}
解决它,看起来互联网需要一个好的,开源的,易于修改的lib,这就是我接下来要做的事情。感谢大家。现在完美运作
答案 1 :(得分:0)
如果另一端的服务返回以CRLF结尾的行,那么从Readline获得的行将在结尾处具有CR。 所以返回的字符串将永远是!=“ - ”。