Ejemplo n.º 1
0
        private void bgMeetDo_handReq(object sender, DoWorkEventArgs e)
        {
            if (!e.Argument.Equals(_handReqStr))
            {
                Console.WriteLine("is busy------------->bgMeetDo_handReq");
                return;
            }
            _doThingStr = _handReqStr;
            string tmpck     = _cookieHeader;
            string ckstr     = _reqCookieStr;
            string urlstr    = _reqUrlSourceStr;
            string body      = _reqBodyStr;
            var    urlAppend = string.Empty;

            if (string.IsNullOrEmpty(urlstr) || !EasyHttpUtils.CheckIsUrlFormat(urlstr))
            {
                _bgMeet.ReportProgress(0, EasyHttpUtils.UnicodeDencode("url格式不正确:" + urlstr));
                return;
            }
            if (!string.IsNullOrEmpty(this._reqUrlAddStr))
            {
                urlAppend = "&" + this._reqUrlAddStr;
            }
            if (!urlstr.Contains(urlAppend))
            {
                urlstr = EasyHttpUtils.RemoveSpace(EasyHttpUtils.ReplaceNewline(urlstr + urlAppend, string.Empty));
            }

            if (!string.IsNullOrEmpty(ckstr))
            {
                tmpck = EasyHttpUtils.RemoveSpace(EasyHttpUtils.ReplaceNewline(ckstr, string.Empty));
            }

            if (!string.IsNullOrEmpty(body))
            {
                body = EasyHttpUtils.RemoveSpace(EasyHttpUtils.ReplaceNewline(body, string.Empty));
            }

            int recount = getReqCount();

            for (int i = 0; i < recount; ++i)
            {
                EasyHttp http = EasyHttp.With(urlstr);
                if (http == null)
                {
                    _bgMeet.ReportProgress(i, EasyHttpUtils.UnicodeDencode("url格式不正确: " + urlstr));
                    return;
                }
                http.LogLevel(EasyHttp.EasyHttpLogLevel.Header);
                //http.Data("code", "9405");
                http.AddHeadersByDic(_reqHeaderDic);
                http.SetCookieHeader(tmpck);
                if (_reqMethod == ReqMethod.POST)
                {
                    //http.PostForStringAsyc(tmpbody);
                    var resStr = http.PostForString(body);
                    _bgMeet.ReportProgress(i, EasyHttpUtils.UnicodeDencode(resStr));
                }
                else
                {
                    //http.GetForStringAsyc();
                    var resStr = http.GetForString();
                    _bgMeet.ReportProgress(i, EasyHttpUtils.UnicodeDencode(resStr));
                }
                //http.OnDataReturn += new EasyHttp.DataReturnHandler(addDataReturn);
            }
        }
Ejemplo n.º 2
0
        private List <DataInfo> paraseTxtString(string txtString)
        {
            List <DataInfo> dataInfoList = new List <DataInfo>();

            if (string.IsNullOrEmpty(txtString))
            {
                return(dataInfoList);
            }

            var __tmpstr = EasyHttpUtils.RemoveSpace(EasyHttpUtils.ReplaceNewline(txtString, string.Empty));

            //Console.WriteLine("去换行:"+ __tmpstr);
            string[] sArray = Regex.Split(__tmpstr, "hcc_cookiePath=", RegexOptions.IgnoreCase);
            int      i      = 0;
            int      j      = 0;

            foreach (string str_1 in sArray)
            {
                if (!string.IsNullOrEmpty(str_1))
                {
                    i++;
                    var cookieStr = string.Empty;
                    var urlStr    = string.Empty;
                    var bodyStr   = string.Empty;

                    //Console.WriteLine("分割(one) " + i.ToString()+ "  :" + str_1);
                    string[] sArray_1 = Regex.Split(str_1, "hcc_fullUrlPath=", RegexOptions.IgnoreCase);
                    foreach (string str_2 in sArray_1)
                    {
                        //Console.WriteLine("分割(two) " + i.ToString() + "  :" + str_2);
                        string[] sArray_2 = Regex.Split(str_2, "hcc_reqBodyPath=", RegexOptions.IgnoreCase);
                        foreach (string str_3 in sArray_2)
                        {
                            j++;
                            //Console.WriteLine("分割(three) " + i.ToString() + "  :" + str_3);
                            //Console.WriteLine("分割(three) " + j.ToString() + "  :" + str_3);
                            if (j % 3 == 0)
                            {
                                _bodyList.Add(str_3);
                            }
                            else if (j % 3 == 1)
                            {
                                _cookieList.Add(str_3);
                            }
                            else if (j % 3 == 2)
                            {
                                _urlList.Add(str_3);
                            }
                        }
                    }
                }
            }

            for (int ct = 0; ct < _cookieList.Count; ct++)
            {
                dataInfoList.Add(new DataInfo(Convert.ToString(ct + 1), _cookieList[ct], _bodyList[ct], _urlList[ct]));
                if (OnTxtReturn != null)
                {
                    //OnTxtReturn.Invoke(this, new DataInfo(Convert.ToString(ct+1), _cookieList[ct], _bodyList[ct],_urlList[ct]));
                }
                else
                {
                    //Console.WriteLine("OnTextReturn == null");
                }
            }
            return(dataInfoList);
        }
Ejemplo n.º 3
0
        private void bgMeetDo_ConfReq(object sender, DoWorkEventArgs e)
        {
            if (!e.Argument.Equals(_confReqStr))
            {
                Console.WriteLine("is busy------------->bgMeetDo_ConfReq");
                return;
            }
            _doThingStr = this._confReqStr;
            if (_dataInfoList.Count <= 0)
            {
                return;
            }
            int recount  = getReqCount();
            int allCount = 0;

            for (int ct = 0; ct < recount; ++ct)
            {
                for (int i = 0; i < _dataInfoList.Count; ++i)
                {
                    allCount++;
                    var url    = _dataInfoList[i].ck_url;
                    var body   = _dataInfoList[i].ck_body;
                    var cookie = _dataInfoList[i].ck_cookie;

                    var urlAppend  = string.Empty;
                    var bodyAppend = this._reqBodyStr;

                    if (!string.IsNullOrEmpty(this._reqUrlAddStr))
                    {
                        urlAppend = "&" + this._reqUrlAddStr;
                    }
                    if (!url.Contains(urlAppend))
                    {
                        url = EasyHttpUtils.RemoveSpace(EasyHttpUtils.ReplaceNewline(url + urlAppend, string.Empty));
                    }

                    if (!string.IsNullOrEmpty(bodyAppend))
                    {
                        body = EasyHttpUtils.RemoveSpace(EasyHttpUtils.ReplaceNewline(bodyAppend, string.Empty));
                    }

                    EasyHttp http = EasyHttp.With(url);
                    if (http == null)
                    {
                        _bgMeet.ReportProgress(allCount, EasyHttpUtils.UnicodeDencode("url出错!"));
                        return;
                    }
                    http.LogLevel(EasyHttp.EasyHttpLogLevel.Header);
                    //http.Data("code", "9405");//请求内容
                    http.AddHeadersByDic(_reqHeaderDic); //添加请求头
                    http.SetCookieHeader(cookie);        //设置cookie
                    if (_reqMethod == ReqMethod.POST)
                    {
                        //http.PostForStringAsyc(body);
                        var resStr = http.PostForString(body);
                        _bgMeet.ReportProgress(allCount, EasyHttpUtils.UnicodeDencode(resStr));
                    }
                    else
                    {
                        //http.GetForStringAsyc();
                        var resStr = http.GetForString();
                        _bgMeet.ReportProgress(allCount, EasyHttpUtils.UnicodeDencode(resStr));
                    }
                    //http.OnDataReturn += new EasyHttp.DataReturnHandler(addDataReturn);
                }
            }
        }