我试图连接到一个Socks5服务器,告诉他连接到一个IMAP服务器并获得一个套接字。我想使用套接字登录到IMAP。我的问题是,在使用SSL流连接到IMAP之后,我只能从流中读取。发送登录数据后,我将不会收到来自IMAP服务器的响应。
这是我的准则:
public static void Main(string[] args)
{
Console.WriteLine("Working *");
var socksClient = new TcpClient();
socksClient.Connect("127.0.0.1", 1080);
var bw = new BinaryWriter(socksClient.GetStream(), Encoding.Default, true);
var br = new BinaryReader(socksClient.GetStream(), Encoding.Default, true);
//Tell the Socks5 to Connect to the IMAP:
//Get the IP of the IMAP
var ip = Dns.GetHostAddresses("mx.freenet.de")[0];
//Me: Hello
bw.Write(new byte[] {0x05, 0x01, 0x00});
//Server: Hello
br.ReadBytes(2);
//Me: Connect to the IMAP on port 993
byte[] data = {0x05, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, getPortBytes(993)[0], getPortBytes(993)[1]};
//Fill the IP in the DATA
for (int i = 0; i < 4; i++)
{
data[i + 4] = ip.GetAddressBytes()[i];
}
bw.Write(data);
//Server: Connection rdy
br.ReadBytes(10);
//Close our old Binary Writer/Reader
br.Close();
br.Dispose();
bw.Close();
bw.Dispose();
//Handle SSL Stream
var ssl = new SslStream(socksClient.GetStream(), false);
//Auth as client
ssl.AuthenticateAsClient("mx.freenet.de", null, SslProtocols.Tls, false);
//Create new Binary Reader/Writer for the SSLStream
var sslBr = new BinaryReader(ssl, Encoding.Default, true);
var sslBw = new BinaryWriter(ssl, Encoding.Default, true);
//Print the IMAP`s Hello
string line = "";
while (true)
{
char c = sslBr.ReadChar();
line += c;
if (c == '\n')
{
Console.WriteLine(line);
break;
}
}
//Send login to IMAP
sslBw.Write((". login fipso@freenet.de HIDDEN"));
//Read response as bytes
while (true)
{
Console.WriteLine(sslBr.ReadByte());
}
/*
Server gives no response.
Why ?
*/
}编辑:运行代码时:
Working *
* OK IMAP ready.发布于 2017-06-09 12:50:33
所有IMAP命令必须以"\r\n“结尾。
看起来您并没有用任何新行来结束您的命令。
https://stackoverflow.com/questions/44454758
复制相似问题