编程语言
首页 > 编程语言> > 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();
复制代码

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

复制代码
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#,HttpWebResponse,HttpWebRequest,request,wp,new,POST,WebProxy
来源: https://www.cnblogs.com/soundcode/p/13729974.html