HttpWebRequest & Session Cookies 
Author Message
 HttpWebRequest & Session Cookies


I am trying to 'Spider' a website and I was hoping someone could help me

Basically I have to POST to a page to login.

This works fine...the HTML I get back shows I am logged in.

It appears the way the site knows you are logged in is via a Session Cookie.

Now, for all future requests I am not sure how to appear as being logged in.

I have something like this:

Function readHtmlPage(ByVal url As String) As String
Dim strResult As String = ""
Dim strPost As String = "username=*****&password=*****&action=login"
Dim myWriter As StreamWriter
      'Dim CookieContainer1 As New CookieContainer
Dim objRequest As HttpWebRequest = WebRequest.Create(url)

objRequest.Method = "POST"
objRequest.ContentLength = strPost.Length
objRequest.ContentType = "application/x-www-form-urlencoded"
      'objRequest.CookieContainer = CookieContainer1

myWriter = New StreamWriter(objRequest.GetRequestStream())
Catch e As Exception
Return e.Message
End Try

Dim objResponse As HttpWebResponse = objRequest.GetResponse()
Dim sr As StreamReader
sr = New StreamReader(objResponse.GetResponseStream())
strResult = sr.ReadToEnd()

Return strResult
End Function

Now, I have heard that using a CookieContainer may be heading in the right
direction...but when I uncomment the CookieContainer code...I get a TimeOut

Anyway...can anyone offer any advice on how I can Grab the Session Cookie
from the login POST request and use it for all future GET requests?

Mon, 14 Nov 2005 07:53:20 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Maintain Session Cookies with HttpWebRequest

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

3. Cookie & Session

4. WebBrowser & session-cookies

5. HttpWebRequest.CookieContainer - HttpWebResponse.Cookies

6. Navigation a site with httpwebrequest & response

7. Convert form post (httpWebRequest) & Catch response

8. Session or cookies

9. browser detection: session cookies

10. cookies or session?

11. Session/Cookie

12. Cookies and Sessions from client side scripts


Powered by phpBB® Forum Software