C# WebProxy POST 或者 GET

代理服务器无账号和密码的代理服务器:

C# WebProxy POST 或者 GET
//创建请求
                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();
C# WebProxy POST 或者 GET

代理服务器有账号和密码的

C# WebProxy POST 或者 GET
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();
C# WebProxy POST 或者 GET

仅仅做代码分析

上一篇:c#-HttpWebRequest / HttpWebResponse的速度


下一篇:如何让ASP.NET网站站点不停止 永远持续运行