代理服务器无账号和密码的代理服务器:
//创建请求 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); //实例化一个WebProxy对象 WebProxy wp = new WebProxy("102.32.75.244:8088"); request.Proxy = wp; //超时时间 request.Timeout = 5000; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gbk")); //读取网页 string code = sr.ReadToEnd();
代理服务器有账号和密码的
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); //实例化一个WebProxy对象 WebProxy wp = new WebProxy(); //代理地址 wp.Address = new Uri("102.32.75.244:8088"); //设置身份验证凭据 账号 密码 wp.Credentials = new NetworkCredential("test123", "123456"); request.Proxy = wp; request.Timeout = 5000; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gbk")); //读取网页 string code = sr.ReadToEnd();
仅仅做代码分析