/// 通过url开启一个EasyHttp public static EasyHttp With(string url) { if (EasyHttpUtils.CheckIsUrlFormat(url)) { string tu = EasyHttpUtils.CheckIsWithHttp(url); try { Uri uri = new Uri(tu); return(With(uri)); } catch (Exception e) { Console.WriteLine("url error:{0}", e.Message); return(null); } } else { Console.WriteLine("error:url is empty or incorrect!"); return(null); } }
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); } }