在 .NET 中使用 Socket,如果连接远端需要通过代理服务器,怎么办?
hebhd 2005-10-17 03:22:43 this.ip=IPAddress.Parse("202.108.22.5");
this.port=80
sb.Append("GET / HTTP/1.1"+"\r\n");
sb.Append("Accept: */*\r\n");
sb.Append("Accept-Language: zh-cn\r\n");
sb.Append("Accept-Encoding: gzip, deflate\r\n");
sb.Append("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; TencentTraveler ; .NET CLR 1.1.4322; .NET CLR 2.0.50215)\r\n");
sb.Append("Host: www.baidu.com\r\n");
sb.Append("Connection: Keep-Alive\r\n\r\n");
System.Net.IPEndPoint ep = new IPEndPoint(this.ip,this.port);
this.socket = new Socket(System.Net.Sockets.AddressFamily.InterNetwork,System.Net.Sockets.SocketType.Stream,System.Net.Sockets.ProtocolType.Tcp);
this.socket.BeginConnect(ep,new AsyncCallback(ConnectCallback),this.socket);
//阻塞当前线程
this.connectdone.WaitOne();
if(this.haveError)
{
return "";
}
//得到请求字符串
this.reqdata = System.Text.Encoding.Default.GetBytes(sb.ToString());
this.socket.BeginSend(this.reqdata,0,this.reqdata.Length,System.Net.Sockets.SocketFlags.None,new AsyncCallback(SendCallback),this.socket);
//阻塞当前线程
senddone.WaitOne();
if(this.haveError || this.sendbytesnum !=this.reqdata.Length)
{
this.socket.Close();
return "";
}
this.socket.BeginReceive(this.readbuff,0,512,0,new AsyncCallback(ReceiveCallback),this.socket);
receivedone.WaitOne();
//显式关闭socket
this.socket.Close();
我要通过代理如何去做。。。。。。