« Remember to install an Application.ThreadException event handler | Main | Event Log custom categories & custom event logs.= »

Bug Report, HttpWebRequest.GetResponse()

The following example program hangs. If the commented line is restored, it exits, but without catching an exception.

In the context of a timer thread, in both console and service projects, execution on the current thread terminates without an exception.

Writing even an empty string is sufficient.

 

namespace Bug.HttpWebRequest.GetResponse

{

      using System;

      using System.Net;

      using System.IO;

 

      class Class1

      {

            [STAThread]

            static void Main(string[] args)

            {

                  try {

                        HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.doesntmatter.com");

                        req.CookieContainer = new CookieContainer();

                        req.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";

                        req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)";

                        req.Headers.Add("Cache-Control:no-cache");

                        req.Headers.Add("Accept-Encoding:gzip, deflate");

                        req.Headers.Add("Accept-Language:en-us");

                        req.Method = "POST";

                        req.ContentType = "application/x-www-form-urlencoded";

                        //StreamWriter sw = new StreamWriter(req.GetRequestStream()); sw.Write("a=1"); sw.Close();

                        req.GetResponse();

                  } catch (Exception ex) {

                        Console.WriteLine("Caught exception.");

                  }

                  Console.WriteLine("Exiting");

            }

      }

}

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)