http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 6879|回复: 11

[其他] HttpHelper类代理IP问题!

[复制链接]
发表于 2013-11-1 10:50:55 | 显示全部楼层 |阅读模式
不用代理是登陆成功的,但是一用代理就报这个错,有点不解!
更多图片 小图 大图
组图打开中,请稍候......


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2013-11-1 10:56:02 | 显示全部楼层
代码跟报错内容在图片里面!{:soso_e101:}
发表于 2013-11-1 11:02:27 | 显示全部楼层
你直接把代理IP放到浏览器里面试试,这有可能是代理IP限制功能的问题,
发表于 2013-11-1 11:02:56 | 显示全部楼层
如果可以,你再设置代理的情况下抓下包进行提交应该就行了
 楼主| 发表于 2013-11-4 10:50:40 | 显示全部楼层
站长苏飞 发表于 2013-11-1 11:02
如果可以,你再设置代理的情况下抓下包进行提交应该就行了

        public static string postMethod(string urlAddr, string postStr, ref CookieContainer cookies, string IP = "", int port = 0, string refer = "")
        {
            string htmlResource = "";
            if (postStr == null || postStr == "")
            {
                Console.WriteLine("post data is empty!");
                return htmlResource;
            }
            if (urlAddr == null || urlAddr == "")
            {
                Console.WriteLine("url addr is empty!");
                return htmlResource;
            }
            HttpWebResponse response = null;
            HttpWebRequest request = null;
            //这一句一定要写在创建连接的前面。使用回调的方法进行证书验证。
            ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
            try
            {
                request = (HttpWebRequest)WebRequest.Create(urlAddr);
                request.ClientCertificates.Add(new X509Certificate("cerify.cer"));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);//显示异常信息
                return htmlResource;
            }
            if (IP != "" && port > 0)
            {
                WebProxy proxyObject = new WebProxy(IP, port);//str为IP地址 port为端口号
                //建议连接
                proxyObject.Credentials = new NetworkCredential("","");
                proxyObject.Credentials = CredentialCache.DefaultCredentials;
                request.Proxy = proxyObject;
            }
            byte[] byteData = Encoding.UTF8.GetBytes(postStr);
            request.Timeout = 300000;
            request.Method = "POST";
            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0";
            request.ContentType = contentType;
            request.KeepAlive = false;
            request.ProtocolVersion = HttpVersion.Version10;
            
            if (refer != "")
            {
                request.Referer = refer;
            }
            request.ContentLength = byteData.Length;
            request.CookieContainer = cookies;
            Stream stream = request.GetRequestStream();
            stream.Write(byteData, 0, byteData.Length);
            stream.Close();
            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);//显示异常信息
                return htmlResource;
            }
            ////查看是否成功
            if (response.StatusCode != HttpStatusCode.OK)
            {
                MessageBox.Show("http response is error!");//显示异常信息
            }
            ///获取返回的结果
            try
            {
                Stream responseStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(responseStream);
                htmlResource = reader.ReadToEnd();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);//显示异常信息
                return htmlResource;
            }
            cookies.Add(response.Cookies);
            return htmlResource;
        }


用这段代码不会保持,但是用HttpHelper类还是报之前那个错!
发表于 2013-11-4 11:20:02 | 显示全部楼层
这直接用Httphelper就行了吧,会不会是你写的Httphelper的代理 那部分代码 有问题啊,你贴出来看看
 楼主| 发表于 2013-11-4 14:01:50 | 显示全部楼层
站长苏飞 发表于 2013-11-4 11:20
这直接用Httphelper就行了吧,会不会是你写的Httphelper的代理 那部分代码 有问题啊,你贴出来看看

            HttpHelper http = new HttpHelper();//登陆
            HttpItem item = new HttpItem()
            {
                URL = "http://11111.cn/login",
                Postdata = "method=name&vwriter="+textBox_user.Text.Trim()+"&vpassword="+textBox_pass.Text.Trim()+"&rmflag=1&returnURL=&fowardURL=",
                Method="post",
                Referer="http://11111.cn/",
                ContentType = "application/x-www-form-urlencoded",
                Timeout=300000,
                UserAgent="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0",
                // ProxyIp = "221.181.192.30:81"
                ProxyIp = "221.181.192.30:81"
            };
            HttpResult result = http.GetHtml(item);
            string ip = item.ProxyIp;
            textBox_return.Text = "";
            cookie = result.Cookie;
            Regex reg = new Regex("登录中");
            Match mat = reg.Match(result.Html);

这是用的HttpHelper类报错,就是楼顶截图的那个错,不懂为啥!!!(不过这个代码如果不用代理的话就不会报错的!)
发表于 2013-11-4 14:20:00 | 显示全部楼层
这个你现在下载一下最后的Httphelper,可以直接设置这个对象WebProxy
 楼主| 发表于 2013-11-4 14:32:04 | 显示全部楼层
站长苏飞 发表于 2013-11-4 14:20
这个你现在下载一下最后的Httphelper,可以直接设置这个对象WebProxy

那之前是什么问题啊?我就郁闷了,唉,没找到有点不舒服,WebProxy是什么概念了?哪里有链接可以了解?
发表于 2013-11-4 15:04:21 | 显示全部楼层
代理对象
         if (IP != "" && port > 0)
            {
                WebProxy proxyObject = new WebProxy(IP, port);//str为IP地址 port为端口号
                //建议连接
                proxyObject.Credentials = new NetworkCredential("","");
                proxyObject.Credentials = CredentialCache.DefaultCredentials;
                request.Proxy = proxyObject;
            }
你代理里不就有用吗?
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-15 08:19

© 2014-2021

快速回复 返回顶部 返回列表