コード例 #1
0
        public HttpResult GetPostData(UrlInfo curUrlObj)
        {
            //创建Httphelper参数对象
            SimpleCrawler.HttpItem item = new SimpleCrawler.HttpItem()
            {
                URL = curUrlObj.UrlString,                         //URL     必需项

                ContentType = "application/x-www-form-urlencoded", //返回类型    可选项有默认值

                Timeout = 1500,
                Accept  = "*/*",
                // Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
                //Encoding = Encoding.Default,
                Method = "post",    //URL     可选项 默认为Get
                //Timeout = 100000,//连接超时时间     可选项默认为100000
                //ReadWriteTimeout = 30000,//写入Post数据超时时间     可选项默认为30000
                //IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写
                //Cookie = "",//字符串Cookie     可选项
                UserAgent = "okhttp/3.2.0",    //用户的浏览器类型,版本,操作系统     可选项有默认值
                //Referer = "app.qichacha.net",//来源URL     可选项
                Postdata = curUrlObj.PostData,
                // Allowautoredirect = true,
                // Cookie = Settings.SimulateCookies
            };


            item.Header.Add("Accept-Encoding", "gzip");
            // item.Header.Add("Host", "app.qichacha.net");
            item.Header.Add("Authorization", curDeviceInfo.accessToken);
            //item.Header.Add("Accept-Language", "zh-CN");
            item.Header.Add("charset", "UTF-8");
            //item.Header.Add("X-Requested-With", "XMLHttpRequest");
            //请求的返回值对象
            item.WebProxy = GetWebProxy();
            var result = http.GetHtml(item);

            return(result);
        }
コード例 #2
0
        public HttpResult GetPostDataKeyWordEnhence(UrlInfo curUrlObj, string refer = "", bool useProxy = true)
        {
            //创建Httphelper参数对象

            //curUrlObj.PostData = string.Format("key=安徽省合肥市荣事达大道568号511室 程华&type=undefined");
            HttpItem item = new HttpItem()
            {
                URL = curUrlObj.UrlString,                                        //URL     必需项

                ContentType = "application/x-www-form-urlencoded; charset=UTF-8", //返回类型    可选项有默认值

                Timeout  = 1500,
                Accept   = "*/*",
                Encoding = null, //编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
                //Encoding = Encoding.Default,
                Method = "post", //URL     可选项 默认为Get
                //Timeout = 100000,//连接超时时间     可选项默认为100000
                //ReadWriteTimeout = 30000,//写入Post数据超时时间     可选项默认为30000
                //IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写
                //Cookie = "",//字符串Cookie     可选项
                UserAgent         = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36", //用户的浏览器类型,版本,操作系统     可选项有默认值
                Referer           = "https://www.qichacha.com/",                                                                                           //来源URL     可选项
                Postdata          = curUrlObj.PostData,
                Allowautoredirect = true,
                Cookie            = globalCookie,
                KeepAlive         = true,
            };

            //item.WebProxy = GetWebProxy();
            item.PostEncoding = System.Text.Encoding.GetEncoding("utf-8");
            var result = http.GetHtml(item);

            if (string.IsNullOrEmpty(result.Html))
            {
            }
            return(result);
        }
コード例 #3
0
        public bool AutoLogout()
        {
            HttpResult result = new HttpResult();

            try
            {
                var item = new HttpItem()
                {
                    URL         = "http://www.qichacha.com/user_logout",
                    Method      = "get",       //URL     可选项 默认为Get
                    ContentType = "text/html", //返回类型    可选项有默认值
                    //Timeout = Settings.Timeout,
                    Cookie = curCookie
                };


                SimpleCrawler.HttpHelper http = new SimpleCrawler.HttpHelper();
                result = http.GetHtml(item);
            }
            catch (WebException ex)
            {
            }
            catch (TimeoutException ex)
            {
            }
            catch (Exception ex)
            {
            }


            if (result.StatusCode == HttpStatusCode.OK)
            {
                // ShowMessageInfo("退出成功");
                // this.webBrowser.Navigate(addCredsToUri(this.textBox.Text));
                return(true);
            }
            else
            {
                // ShowMessageInfo("退出失败");
                return(false);
            }
        }
コード例 #4
0
        private string GetHttpResult(UrlInfo urlInfo)
        {
            urlInfo = UrlInfoFix(urlInfo);
            var url = urlInfo.UrlString;

            HttpHelper http = new HttpHelper();
            HttpItem   item = null;

            item = new HttpItem()
            {
                URL = url,                 //URL     必需项
                //URL = "http://luckymn.cn/QuestionAnswer",
                Method      = "get",       //URL     可选项 默认为Get
                ContentType = "text/html", //返回类型    可选项有默认值
                Timeout     = this.Settings.Timeout,
                UserAgent   = this.Settings.UserAgent,
            };


            // item.Header.Add("Accept", "text/html, application/xhtml+xml, */*");


            if (!string.IsNullOrEmpty(urlInfo.PostData))
            {
                item.Method   = "post";
                item.Postdata = urlInfo.PostData;
            }


            if (Settings.CurWebProxy != null)
            {
                item.WebProxy = Settings.CurWebProxy;
            }
            else
            {
                var curIPProxy = Settings.GetIPProxy();
                if (curIPProxy != null)
                {
                    item.ProxyIp = curIPProxy.IP;
                }
            }
            if (!string.IsNullOrEmpty(this.Settings.SimulateCookies))
            {
                item.Cookie = this.Settings.SimulateCookies;
            }
            if (!string.IsNullOrEmpty(this.Settings.ContentType))
            {
                item.ContentType = this.Settings.ContentType;
            }
            if (!string.IsNullOrEmpty(this.Settings.Referer))
            {
                item.Referer = this.Settings.Referer;
            }
            if (this.Settings.PostEncoding != null)
            {
                item.PostEncoding = this.Settings.PostEncoding;
            }
            if (!string.IsNullOrEmpty(this.Settings.ContentType))
            {
                item.ContentType = this.Settings.ContentType;
            }
            if (!string.IsNullOrEmpty(this.Settings.Accept))
            {
                item.Accept = this.Settings.Accept;
            }
            if (!string.IsNullOrEmpty(urlInfo.Authorization))
            {
                item.Header.Add("Authorization", urlInfo.Authorization);
            }

            try
            {
                if (Settings.HeadSetDic != null)
                {
                    foreach (var key in Settings.HeadSetDic.Keys)
                    {
                        item.Header.Add(key, Settings.HeadSetDic[key]);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("GetHttpResult:" + ex.Message);
            }
            //添加代理ip列表,随机挑选ip
            //创建并配置Web请求
            //request = WebRequest.Create(urlInfo.UrlString) as HttpWebRequest;
            //curIPProxy = this.ConfigRequest(request);//返回当前的代理地址
            var result = http.GetHtml(item);

            return(result.Html);
        }