我正试图找到一些代理的性能。我在.net中尝试了Ping
类,但它不接受端口。有没有办法检查httpwebrequest
的响应时间?
答案 0 :(得分:22)
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;
答案 1 :(得分:17)
为什么不从客户端计算它?
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);