locked
Keep-Alive is missing in header RRS feed

  • Question

  • User1455845355 posted

    Hi,

    I am trying to access a website programatically using Httpwebrequest.

    I have set KeepAlive = true but it is missing in header when the url is redirected.

    Please let me know how to persist it.

    My code:


    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sWebAddress);
                request.Credentials = new NetworkCredential("username", "pwd", "domain");
                CookieContainer cookieJar = new CookieContainer();
                request.CookieContainer = cookieJar;            
                request.Accept = "*/*";
                request.Headers.Add("Accept-Language", "en-us");
                request.Headers.Add("Accept-Encoding", "gzip, deflate");
                request.KeepAlive = true;           
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
                
                // Get the response.
                WebResponse response = request.GetResponse();

                Stream dataStream = response.GetResponseStream();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                responseFromServer = reader.ReadToEnd();            
                // Clean up the streams.
                reader.Close();
                dataStream.Close();
                response.Close();


    Thanks in advance.

    Regards,

    Rajiv.

    Thursday, December 3, 2009 10:04 AM

All replies