Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

December 10, 2007

HTTP 500 - Server Too Busy

Question:
I am evaluating your HTTP component and I’m getting some interesting results using your component.

I am calling a GET to just grab the HTML for a web page.

After about 8 calls to the website using the Chilkat.Http.QuickGetStr(), the website returns that it’s busy. However, if I replicate the same thing using the built in System.Net.WebClient, the website never returns it’s busy. The sample code is below. What is the Chilkat client doing differently? Is the software limited?

            foreach (string password in passwords)
            {
                Chilkat.Http http = new Chilkat.Http();
                http.MaxConnections = 100;
                bool unlocked = http.UnlockComponent("Any string begins 30-day trial");
                if (!unlocked)
                {
                    Console.Out.WriteLine("Failed to unlock HTTP component");
                    return;
                }
                string html = http.QuickGetStr("http://localhost/administration/login.aspx");
                Console.WriteLine(password);
                Console.WriteLine(html);
            }
	
            foreach (string password in passwords)
            {
                WebClient client = new WebClient();
                Stream data = client.OpenRead (" http://localhost/administration/login.aspx");
                StreamReader reader = new StreamReader (data);
                string s = reader.ReadToEnd ();
                Console.WriteLine(password);
                Console.WriteLine (s.Substring(1,50));
                data.Close ();
                reader.Close ();
}

Answer:

The problem is that you’re accumulating open connections with the web server. The Chilkat.HTTP object will keep the N most recently used connections open (if possible) so that subsequent GET requests do not need to re-establish a TCP/IP connection with the HTTP server. The MaxConnections property controls how many open connections are maintained.

The code snippet above creates a new instance of the Chilkat.Http component in each iteration of the loop. Moving it to outside the loop would fix the problem:

            Chilkat.Http http = new Chilkat.Http();
            http.MaxConnections = 100;
            bool unlocked = http.UnlockComponent("Any string begins 30-day trial");
            if (!unlocked)
                {
                    Console.Out.WriteLine("Failed to unlock HTTP component");
                    return;
                }
            foreach (string password in passwords)
            {
                 string html = http.QuickGetStr("http://localhost/administration/login.aspx");
                Console.WriteLine(password);
                Console.WriteLine(html);
            }

Alternatively, the connection is closed with the destruction of the object. If you force the .NET garbage collection to run, that would also solve the problem:

            foreach (string password in passwords)
            {
                Chilkat.Http http = new Chilkat.Http();
                http.MaxConnections = 100;
                bool unlocked = http.UnlockComponent("Any string begins 30-day trial");
                if (!unlocked)
                {
                    Console.Out.WriteLine("Failed to unlock HTTP component");
                    return;
                }
                string html = http.QuickGetStr("http://localhost/administration/login.aspx");
                Console.WriteLine(password);
                Console.WriteLine(html);
	
                // Force the Chilkat.Http object to be destructed, which closes all potentially open connections.
                http = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.