C#做的通过http读取一个网页的内容的程序,请问如果用代理,怎么做呢?不用代理的代码是这样写的,改用用代理的该怎么写呢?我自己写了下,不成功.
private void SendRequestData(string URL, string method, bool showProgress)
{
clientSocket = new TcpClient();
Uri URI = new Uri(URL);
clientSocket.Connect(URI.Host, URI.Port); /***********可以用代理的,这种试式不成功***********/
//clientSocket = new TcpClient();
//Uri URI;
//WebProxy proxy = WebProxy.GetDefaultProxy();//获取IE缺省设置
////BasicHttpBinding binding = new BasicHttpBinding();
//if (proxy.Address != null)//== null && binding.ProxyAddress != null
// URI = proxy.Address;
//else
// URI = new Uri(URL);
//clientSocket.Connect(URI.Host, URI.Port);
/***************************/
requestHeaders.Add("Host", URI.Host);
byte[] request = GetRequestHeaders(method + " " + URI.PathAndQuery + " HTTP/1.1");
clientSocket.Client.Send(request);
//..........
}
private void SendRequestData(string URL, string method, bool showProgress)
{
clientSocket = new TcpClient();
Uri URI = new Uri(URL);
clientSocket.Connect(URI.Host, URI.Port); /***********可以用代理的,这种试式不成功***********/
//clientSocket = new TcpClient();
//Uri URI;
//WebProxy proxy = WebProxy.GetDefaultProxy();//获取IE缺省设置
////BasicHttpBinding binding = new BasicHttpBinding();
//if (proxy.Address != null)//== null && binding.ProxyAddress != null
// URI = proxy.Address;
//else
// URI = new Uri(URL);
//clientSocket.Connect(URI.Host, URI.Port);
/***************************/
requestHeaders.Add("Host", URI.Host);
byte[] request = GetRequestHeaders(method + " " + URI.PathAndQuery + " HTTP/1.1");
clientSocket.Client.Send(request);
//..........
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货