Results 1 to 5 of 5

Thread: [2008] Navigating webpages

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    417

    [2008] Navigating webpages

    Hi Guys,

    I have tweaked my code and am able to login great to my website, but i'm not sure in regards to exactly hand how to navigate to anothe rpage once logged in

    code:

    Code:
                'Make a request for the desired web page
                Dim varRequest As HttpWebRequest = CType(WebRequest.Create("http://www.XXXX.com/login.html"), HttpWebRequest)
                Dim cookie As New CookieContainer
                Dim varCookieContainer As New Net.CookieContainer
                Dim varPostData As String = "username=graham23s&password=XXXXXXXX&remember=1&submit=Submit"
                Dim varBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(varPostData)
    
                varRequest.Method = "POST"
                varRequest.KeepAlive = True
                varRequest.AllowAutoRedirect = True
                varRequest.ContentType = "application/x-www-form-urlencoded"
                varRequest.ContentLength = varBytes.Length
                varRequest.CookieContainer = varCookieContainer
    
                Dim varStream = varRequest.GetRequestStream()
                varStream.Write(varBytes, 0, varBytes.Length)
                varStream.Close()
    
                Dim varRequest2 As HttpWebRequest = CType(WebRequest.Create("http://www.XXXX.com/bm_edit.html"), HttpWebRequest)
                Dim cookie2 As New CookieContainer
                Dim varCookieContainer2 As New Net.CookieContainer
                Dim varPostData2 As String = "username=graham23s&password=XXXXXXXX&remember=1&submit=Submit"
                Dim varBytes2 As Byte() = System.Text.Encoding.UTF8.GetBytes(varPostData)
    
    
    
                Dim response As HttpWebResponse = CType(varRequest.GetResponse(), HttpWebResponse)
                Dim sr As New System.IO.StreamReader(response.GetResponseStream)
                Dim HTMLResponse As String = Trim(sr.ReadToEnd())
    
                'Display the html source code
                debugTextBox.Text = HTMLResponse
                response.Close()
                sr.Close()
    do i make another request once logged in? or will that lose the session/cookies?

    thanks for any help guys

    Graham

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2008] Navigating webpages

    Depends on how your website works, but if you use the same cookie container across your calls, that might work for you.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    417

    Re: [2008] Navigating webpages

    Hi N,

    Yeah it uses cookies

    this code:

    Code:
                'Make a request for the desired web page
                Dim varRequest As HttpWebRequest = CType(WebRequest.Create("http://www.XXXXXXXX.com/login.html"), HttpWebRequest)
                Dim cookie As New CookieContainer
                Dim varCookieContainer As New Net.CookieContainer
                Dim varPostData As String = "username=graham23s&password=XXXXXXXX&remember=1&submit=Submit"
                Dim varBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(varPostData)
    
                varRequest.Method = "POST"
                varRequest.KeepAlive = True
                varRequest.AllowAutoRedirect = True
                varRequest.ContentType = "application/x-www-form-urlencoded"
                varRequest.ContentLength = varBytes.Length
                varRequest.CookieContainer = varCookieContainer
    
                Dim varStream = varRequest.GetRequestStream()
                varStream.Write(varBytes, 0, varBytes.Length)
                varStream.Close()
    Logs me in great, it's where exactly to add the request for the second page i'm kinda stuck on

    code:

    Code:
                'Make a request for the desired web page
                Dim varRequest As HttpWebRequest = CType(WebRequest.Create("http://www.XXXXXXXX.com/login.html"), HttpWebRequest)
                Dim cookie As New CookieContainer
                Dim varCookieContainer As New Net.CookieContainer
                Dim varPostData As String = "username=graham23s&password=XXXXXXXX&remember=1&submit=Submit"
                Dim varBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(varPostData)
    
                varRequest.Method = "POST"
                varRequest.KeepAlive = True
                varRequest.AllowAutoRedirect = True
                varRequest.ContentType = "application/x-www-form-urlencoded"
                varRequest.ContentLength = varBytes.Length
                varRequest.CookieContainer = varCookieContainer
    
                Dim varStream = varRequest.GetRequestStream()
                varStream.Write(varBytes, 0, varBytes.Length)
                varStream.Close()
    would i just add another:

    Dim varRequest As HttpWebRequest = CType(WebRequest.Create("http://www.XXXXXXXX.com/anotherpage.html"), HttpWebRequest)

    after this part or is there a bit more coding involved lol

    varRequest.CookieContainer = varCookieContainer


    Thanks mate

    Graham

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2008] Navigating webpages

    Just make a new web request, but use the same cookie container that you used for the initial request.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    417

    Re: [2008] Navigating webpages

    Thank N will do, appreciate the guidance

    Graham

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width