【发布时间】:2013-09-05 12:06:36
【问题描述】:
在开发一个开源代理脚本时,一段代码如下: 静态无效主要(字符串 [] 参数) { 字符串主机=“www.google.com”; int proxyPort = 443;//443;
byte[] buffer = new byte[2048];
int bytes;
// Connect socket
TcpClient client = new TcpClient(host, proxyPort);
NetworkStream stream = client.GetStream();
byte[] tunnelRequest = Encoding.UTF8.GetBytes(String.Format("CONNECT www.google.com:443 HTTP/1.1\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.1; rv:23.0) Gecko/20100101 Firefox/23.0\r\nProxy-Connection: keep-alive\r\nConnection: keep-alive\r\nHost: www.google.com\r\n\r\n", host));
stream.Write(tunnelRequest, 0, tunnelRequest.Length);
stream.Flush();
SslStream sslStream = new SslStream(stream);
sslStream.AuthenticateAsClient(host);
}
当我运行代码时,在这一行出现错误:sslStream.AuthenticateAsClient(host); 错误的解释是:无法从传输连接中读取数据。现有连接被远程主机强行关闭。 或此错误:验证失败,因为远程方已关闭传输流。 请帮我 谢谢
【问题讨论】:
-
与其自己编写大约 20k 行代码,不如直接使用 FiddlerCore (fiddler2.com/core)?