• C# 调用httpwatch接口基础使用方法


    (1)安装httpwatch; 

    (2)打开c#工程,在“引用”中增加“COM”组件,在“COM”组件中找到“HttpWatch Professional 7.2 Automation Libary”,确定。(7.2为我安装的httpwatch版本) 

    (3)copy代码 

    C#代码  收藏代码
    1. using System;  
    2. using HttpWatch;  
    3.   
    4. namespace page_check  
    5. {  
    6.     class PageChecker  
    7.     {  
    8.         [STAThread]  
    9.         static void Main(string[] args)  
    10.         {  
    11.             Console.WriteLine("Enter the URL of the page to check (press enter for http://www.baidu.com/):\r\n");  
    12.             string url = Console.ReadLine();  
    13.             if ( url.Length == 0 )    
    14.                 url = "http://www.baidu.com/";  
    15.               
    16.             Console.WriteLine("\r\nChecking " + url + "...\r\n");  
    17.   
    18.             // Create a new instance of HttpWatch in IE  
    19.             Controller control = new Controller();  
    20.             Plugin plugin = control.IE.New();  
    21.   
    22.             // Start Recording HTTP traffic  
    23.             plugin.Log.EnableFilter(false);  
    24.             plugin.Record();  
    25.   
    26.             // Goto to the URL and wait for the page to be loaded  
    27.             plugin.GotoURL(url);  
    28.             control.Wait(plugin, -1);  
    29.   
    30.             // Stop recording HTTP  
    31.             plugin.Stop();  
    32.   
    33.             if (plugin.Log.Pages.Count != 0)  
    34.             {  
    35.                 Console.WriteLine("\r\nPage Title: '" + plugin.Log.Pages[0].Title + "'");  
    36.   
    37.                 Console.WriteLine();  
    38.   
    39.                 // Display summary statistics for page  
    40.                 Summary summary = plugin.Log.Pages[0].Entries.Summary;  
    41.                 Console.WriteLine("Total time to load page (secs):      " + summary.Time);  
    42.                 Console.WriteLine("Number of bytes received on network: " + summary.BytesReceived);  
    43.                 Console.WriteLine("HTTP compression saving (bytes):     " + summary.CompressionSavedBytes);  
    44.                 Console.WriteLine("Number of round trips:               " + summary.RoundTrips);  
    45.                 Console.WriteLine("Number of errors:                    " + summary.Errors.Count);  
    46.   
    47.                 Console.WriteLine("-----------------------",plugin.Log.Entries.Count);  
    48.   
    49.                 //Entries e = plugin.Log.Entries;  
    50.                 for (int i=0; i<plugin.Log.Entries.Count; i++)   
    51.                 {  
    52.                     Console.Write(plugin.Log.Entries[i].URL);  
    53.                     Console.WriteLine(" " + plugin.Log.Entries[i].Time);  
    54.                 }  
    55.             }  
    56.             // Close down IE  
    57.             plugin.CloseBrowser();  
    58.   
    59.             Console.WriteLine( "\r\nPress Enter to exit");  
    60.             Console.ReadLine();  
    61.         }  
    62.     }  
    63. }  



    (4)运行 

    完成!

  • 相关阅读:
    jascript基础教程学习总结(2)
    ajax原理图解
    ajax原理
    javascript基础教程学习总结(1)
    HTML学习(1)
    vi编辑器
    effective C++ 4 Make sure objects are initialized before they are used
    effective C++ 3 use const whenever possible
    STL: string:erase
    STL: 从reverse到iterator
  • 原文地址:https://www.cnblogs.com/ArRan/p/2767725.html
Copyright © 2020-2023  润新知