request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
Stream requestStream = request.GetRequestStream();
byte[] byteArray = Encoding.UTF8.GetBytes(data);
requestStream.Write(byteArray, 0, byteArray.Length);
requestStream.Close();
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Uri responseUri = response.ResponseUri;
Stream receiveStream = response.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader(receiveStream, encode);
string result = readStream.ReadToEnd();
info = result;
return 0; }
public static bool GetBool(string html)
{ Regex regtable = new Regex(@"http://img.dotad.net/lg.gif", RegexOptions.Singleline);
Match ma = regtable.Match(html);
if (ma.Success)
{
return true;
}
else
return false;
} public static void ThreadProc()
{ string info = "";
string data = "";
string url = "http://203.86.46.53/lg/index.aspx";
long i=0;
HiPerfTimer pt = new HiPerfTimer(); // create a new PerfTimer object
pt.Start(); // start the timer
while (i++<100)
{
PostData(url, data, out info);
//System.Console.WriteLine(info);
if (GetBool(info) == true)
{
rt++;
}
else
{
wr++;
}
}
pt.Stop();
System.Console.WriteLine("成功" + rt + " 次,失败 " + wr + " 次\n");
Console.WriteLine("用时: {0} sec\n",
pt.Duration); // print the duration of the timed code
} static void Main(string[] args)
{
Console.WriteLine("Test\n"); // the code to be timed
long j = 0;
while(j++<15)
{
Thread t = new Thread(new ThreadStart(ThreadProc));
t.Start();
}
}
}
}
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/