使用HTTPWebRequest检查响应时间?

我试图找到我的一些代理的性能。 我在.net中尝试过Ping类,但它不接受端口。 有没有办法检查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; 

为什么不从客户端计算它?

 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);