(1)安装httpwatch;
(2)打开c#工程,在“引用”中增加“COM”组件,在“COM”组件中找到“HttpWatch Professional 7.2 Automation Libary”,确定。(7.2为我安装的httpwatch版本)
(3)copy代码
- using System;
- using HttpWatch;
- namespace page_check
- {
- class PageChecker
- {
- [STAThread]
- static void Main(string[] args)
- {
- Console.WriteLine("Enter the URL of the page to check (press enter for http://www.baidu.com/):\r\n");
- string url = Console.ReadLine();
- if ( url.Length == 0 )
- url = "http://www.baidu.com/";
- Console.WriteLine("\r\nChecking " + url + "...\r\n");
- // Create a new instance of HttpWatch in IE
- Controller control = new Controller();
- Plugin plugin = control.IE.New();
- // Start Recording HTTP traffic
- plugin.Log.EnableFilter(false);
- plugin.Record();
- // Goto to the URL and wait for the page to be loaded
- plugin.GotoURL(url);
- control.Wait(plugin, -1);
- // Stop recording HTTP
- plugin.Stop();
- if (plugin.Log.Pages.Count != 0)
- {
- Console.WriteLine("\r\nPage Title: '" + plugin.Log.Pages[0].Title + "'");
- Console.WriteLine();
- // Display summary statistics for page
- Summary summary = plugin.Log.Pages[0].Entries.Summary;
- Console.WriteLine("Total time to load page (secs): " + summary.Time);
- Console.WriteLine("Number of bytes received on network: " + summary.BytesReceived);
- Console.WriteLine("HTTP compression saving (bytes): " + summary.CompressionSavedBytes);
- Console.WriteLine("Number of round trips: " + summary.RoundTrips);
- Console.WriteLine("Number of errors: " + summary.Errors.Count);
- Console.WriteLine("-----------------------",plugin.Log.Entries.Count);
- //Entries e = plugin.Log.Entries;
- for (int i=0; i<plugin.Log.Entries.Count; i++)
- {
- Console.Write(plugin.Log.Entries[i].URL);
- Console.WriteLine(" " + plugin.Log.Entries[i].Time);
- }
- }
- // Close down IE
- plugin.CloseBrowser();
- Console.WriteLine( "\r\nPress Enter to exit");
- Console.ReadLine();
- }
- }
- }
(4)运行
完成!