【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
Http请求中,代理是我们比较常见的使用方法,一他可以隐藏自己的IP,再就是可以动态的改变IP,不像之前一直使用Adsl不断的断开,连接,现在的ADSL都是有限制,没办法一直下去。
比如说你要给一个页面增加IP量,或者是Pv量。你就可以找上成千上万个IP进行刷流量。
再比如有个网站限制每IP操作一次,那如果你想多次操作就可以使用代理IP来解决。
第一种设置不带账户密码的代理IP
//创建Httphelper对象
HttpHelper http = new HttpHelper();
//创建Httphelper参数对象
HttpItem item = new HttpItem()
{
URL = "http://www.sufeinet.com",//URL 必需项
Method = "get",//URL 可选项 默认为Get
ContentType = "text/html",//返回类型 可选项有默认值
ProxyIp = "192.168.1.18:2011",
};
//请求的返回值对象
HttpResult result = http.GetHtml(item);
//获取请请求的Html
string html = result.Html;
//获取请求的Cookie
string cookie = result.Cookie;
第二种是设置带账户密码的代理IP
//创建Httphelper对象
HttpHelper http = new HttpHelper();
//创建Httphelper参数对象
HttpItem item = new HttpItem()
{
URL = "http://www.sufeinet.com",//URL 必需项
Method = "get",//URL 可选项 默认为Get
ContentType = "text/html",//返回类型 可选项有默认值
ProxyIp = "192.168.1.18:2011",
ProxyUserName = "admin",
ProxyPwd = "123456"
};
//请求的返回值对象
HttpResult result = http.GetHtml(item);
//获取请请求的Html
string html = result.Html;
//获取请求的Cookie
string cookie = result.Cookie;
第三种是设置自定义类型的代理IP
WebProxy myProxy = new WebProxy("192.168.15.11", 8015);
//建议连接
myProxy.Credentials = new NetworkCredential("admin", "123456");
//创建Httphelper对象
HttpHelper http = new HttpHelper();
//创建Httphelper参数对象
HttpItem item = new HttpItem()
{
URL = "http://www.sufeinet.com",//URL 必需项
Method = "get",//URL 可选项 默认为Get
ContentType = "text/html",//返回类型 可选项有默认值
WebProxy = myProxy
};
//请求的返回值对象
HttpResult result = http.GetHtml(item);
//获取请请求的Html
string html = result.Html;
//获取请求的Cookie
string cookie = result.Cookie;
收集以备用。