标题: 支持C#,Ruby,JavaScript(API)的HttpWatch 5.x
- overred 2007-08-10 01:32 阅读:1843
- 评论:2 查看评论 | 添加评论

下载地址:http://www.httpwatch.com/download/
http://www.httpwatch.com/rubywatir/
对于取一些网站信息的朋友来说无疑是个好消息。
具体使用见安装后佩带的Demo
专业版支持所有,基本版就只能浏览一些基本信息
[图片]

示例代码:
// Page Check C# Example
// 
// For more information about this example please refer to the readme.txt file in the
// same directory
//
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 www.microsoft.com):\r\n");
            string url = Console.ReadLine();
            if ( url.Length == 0 )    
                url = "www.microsoft.com";
            
            Console.WriteLine("\r\nChecking " + url + "[图片]\r\n");

            // Create a new instance of HttpWatch in IE
            ControllerClass control = new ControllerClass();
            Plugin plugin = control.New();

            // Uncomment the next line to hide the new IE window
            // plugin.Container.Visible = false;

            // 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();
            
            // Look at each HTTP request in the log to compile statistics
            int roundTrips = 0, bytesReceived = 0, errors = 0, compressedSaved = 0;
            int compressionNotChecked = 0;
            double timeTaken = 0;
            foreach( Entry entry in plugin.Log)
            {
                // Keep track of last request to complete
                if ( entry.StartedSecs + entry.Time > timeTaken )
                {
                    timeTaken = entry.StartedSecs + entry.Time;
                }

                if ( entry.BytesReceived != 0 )
                {
                    ++roundTrips;
                    bytesReceived += entry.BytesReceived;
                }
                if ( (entry.Error.Length != 0 && entry.Error != "Aborted") || entry.StatusCode >= 400)
                {
                    ++errors;
                }

                // If extended HTTP information is available[图片]
                if ( !entry.IsRestrictedURL )
                {
                    // Calculate the compression savings
                    if ( entry.Content.IsCompressed )
                    {
                        compressedSaved += entry.Content.Size - entry.Content.CompressedSize;
                    }
                }
                else
                {
                    ++compressionNotChecked;
                }
            }
            // Close down IE
            plugin.Container.Quit();

            Console.WriteLine( "Total time to load page (secs):      " + timeTaken);
            Console.WriteLine( "Number of bytes received on network: " + bytesReceived);

            Console.WriteLine( "HTTP compression saving (bytes):     " + compressedSaved);
            Console.WriteLine( "Number of round trips:               " + roundTrips);
            Console.WriteLine( "Number of errors:                    " + errors);

            if ( control.IsBasicEdition && compressionNotChecked != 0)
            {
                Console.WriteLine( "\r\n(Compression was not checked in " + compressionNotChecked +
                                   " requests because the URLs are not supported in HttpWatch Basic Edition)");
            }

            Console.WriteLine( "\r\nPress Enter to exit");
            Console.ReadLine();
        }
    }
}

http://www.zishuo.cn/Archives/HttpWatch.aspx
查看评论 | 添加评论
返回顶部 | 返回首页