【发布时间】:2011-10-25 18:17:00
【问题描述】:
我正在尝试查找我的一些代理的性能。我在.net 中尝试了Ping 类,但它不接受端口。有没有办法检查httpwebrequest 的回复需要多长时间?
【问题讨论】:
标签: c# .net httpwebrequest
我正在尝试查找我的一些代理的性能。我在.net 中尝试了Ping 类,但它不接受端口。有没有办法检查httpwebrequest 的回复需要多长时间?
【问题讨论】:
标签: c# .net httpwebrequest
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(myUri);
System.Diagnostics.Stopwatch timer = new Stopwatch();
timer.Start();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Close ();
timer.Stop();
TimeSpan timeTaken = timer.Elapsed;
【讨论】:
foreach (DataRow dr in dt.Rows) { ........ }
为什么不直接从客户端计时呢?
WebRequest request = BuildRequest();
Stopwatch sw = Stopwatch.StartNew();
using (WebResponse response = request.GetResponse())
{
// Potentially fetch all the data here, in case it's streaming...
}
sw.Stop();
Console.WriteLine("Request took {0}", sw.Elapsed);
【讨论】:
Stopwatch。我不确定我明白你在问什么......