Maintain Session Cookies with HttpWebRequest 
Author Message
 Maintain Session Cookies with HttpWebRequest

I am attempting to download Html from a remote web application. This
web application uses two session cookies, one for session id and the
other for state. I need to maintain these session cookies across two
or more requests. I understand that I must use HttpWebRequest for
this, but unfortunately cannot get the code to work correctly. The
following code does download Html. The problem is that the Html is the
web application telling me to enable cookies.

All suggestions appreciated,
J Wolfgang Goerlich

 '- Dimension Variables

 Dim CookieJar As New CookieCollection()
 Dim Html As String
 Dim Request As HttpWebRequest
 Dim Response As HttpWebResponse
 Dim s As System.IO.Stream
 Dim sr As System.IO.StreamReader
 Dim Url As System.Uri

 '- Build Http Request

 Url = New System.Uri(StringUrl)
 Request = WebRequest.Create(Url)
 Request.CookieContainer = New CookieContainer()
 Request.Method = "GET"
 Request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.0; .NET CLR 1.0.3705)"

 '- Send Http Request and receive Http Response

 Response = Request.GetResponse()
 CookieJar = Response.Cookies
 Request.CookieContainer.Add(CookieJar)

 '- Read the Html

 s = Response.GetResponseStream
 sr = New System.IO.StreamReader(s)
 Html = sr.ReadToEnd()

 '- Cleanup

 sr.Close()
 sr = Nothing
 Response.Close()
 Response = Nothing
 Request = Nothing
 Return Html



Wed, 28 Sep 2005 04:35:07 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. HttpWebRequest & Session Cookies

2. HttpWebRequest.CookieContainer - HttpWebResponse.Cookies

3. HELP! Wireless needs to maintain session

4. Maintaining user settings between sessions

5. Help on IE Browser integration with VB (Maintaining sessions between windows)

6. VB.NET - Session Tracking with & without Cookies

7. Session or cookies

8. browser detection: session cookies

9. cookies or session?

10. Session/Cookie

11. Cookies and Sessions from client side scripts

12. Global file and session cookies

 

 
Powered by phpBB® Forum Software