public HttpEntity getHttpEntityFromUrlGET(String urlStr) { ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return(true); }); HttpEntity ret = new HttpEntity(); ret.Url = urlStr; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ret.Url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { TextReader reader = new StreamReader(response.GetResponseStream()); ret.Response = reader.ReadToEnd(); ret.Length = ret.Response.Length; } else { throw new Exception(response.StatusCode.ToString()); } ret.Status = response.StatusCode; } catch (Exception e) { ret.Exception = e; ret.Status = HttpStatusCode.RequestTimeout; } return(ret); }
public void run() { activeTlabel.Invoke(new IgnitionForm.UpdateTextCallbackT(this.IncreaseFormItemText), new object[] { activeTlabel }); for (int i = 0; i < times; i++) { HttpEntity httpEntity = null; if (seed.method == "GET") { httpEntity = Utils.Instance.getHttpEntityFromUrlGET(seed.protocol, seed.domain, seed.address, seed.randn, seed.rands); } else { httpEntity = Utils.Instance.getHttpEntityFromUrlPOST(seed.protocol, seed.domain, seed.address, seed.randn, seed.rands); } if (httpEntity.Status == System.Net.HttpStatusCode.OK) { srL.Invoke(new IgnitionForm.UpdateTextCallbackT(this.IncreaseFormItemText), new object[] { srL }); Interlocked.Increment(ref IgnitionForm.rd); IgnitionForm.rd = IgnitionForm.rd + httpEntity.Length; Interlocked.Increment(ref IgnitionForm.ud); IgnitionForm.ud = IgnitionForm.ud + httpEntity.Url.Length; dLen.Invoke(new IgnitionForm.IncreaseLabelBytes(this.IncreaseLabelBytes), new object[] { dLen, IgnitionForm.rd }); uLen.Invoke(new IgnitionForm.IncreaseLabelBytes(this.IncreaseLabelBytes), new object[] { uLen, IgnitionForm.ud }); } else { srL.Invoke(new IgnitionForm.UpdateTextCallbackT(this.IncreaseFormItemText), new object[] { urL }); } String message = "Thread " + id + "/" + i + " started. (" + seed.method + " " + httpEntity.Url + ")"; logBox.Invoke(new IgnitionForm.UpdateTextCallback(this.UpdateFormItemText), new object[] { message }); } activeTlabel.Invoke(new IgnitionForm.UpdateTextCallbackT(this.DecreaseFormItemText), new object[] { activeTlabel }); if (activeTlabel.Text == "0") { plantBt.Invoke(new IgnitionForm.ReleaseUi(this.ReleaseUi), null); } }
public HttpEntity getHttpEntityFromUrlGET(String protocol, String baseUrl, String baseParams, int nSize, int sSize) { ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return(true); }); HttpEntity ret = new HttpEntity(); try { String[] paramsParts = baseParams.Split('&'); StringBuilder sb = new StringBuilder(); sb.Append(protocol + "://" + baseUrl + "?"); NameValueCollection paramsCollection = new NameValueCollection(); foreach (String item in paramsParts) { String[] preCol = item.Split('='); sb.Append(preCol[0] + "=" + genRandParamValues(preCol[0], preCol[1], nSize, sSize) + "&"); } ret.Url = sb.ToString(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ret.Url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { TextReader reader = new StreamReader(response.GetResponseStream()); ret.Response = reader.ReadToEnd(); ret.Length = ret.Response.Length; } else { throw new Exception(response.StatusCode.ToString()); } ret.Status = response.StatusCode; } catch (Exception e) { //throw e; ret.Exception = e; ret.Status = HttpStatusCode.RequestTimeout; } return(ret); }
public HttpEntity getHttpEntityFromUrlPOST(String protocol, String baseUrl, String baseParams, int nSize, int sSize) { ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return(true); }); HttpEntity ret = new HttpEntity(); using (WebClient client = new WebClient()) { String[] paramsParts = baseParams.Split('&'); StringBuilder sb = new StringBuilder(); String separator = "?"; if (baseUrl.Contains("?")) { separator = "&"; } sb.Append(protocol + "://" + baseUrl + separator); NameValueCollection paramsCollection = new NameValueCollection(); foreach (String item in paramsParts) { String[] preCol = item.Split('='); paramsCollection.Add(preCol[0], genRandParamValues(preCol[0], preCol[1], nSize, sSize)); sb.Append(preCol[0] + "=" + genRandParamValues(preCol[0], preCol[1], nSize, sSize) + "&"); } ret.Url = sb.ToString(); try { byte[] response = client.UploadValues(protocol + "://" + baseUrl, paramsCollection); string result = System.Text.Encoding.UTF8.GetString(response); ret.Response = result; ret.Length = result.Length; ret.Status = HttpStatusCode.OK; } catch (Exception e) { ret.Exception = e; ret.Status = HttpStatusCode.RequestTimeout; } } return(ret); }