Results 1 to 7 of 7

Thread: Webrequest + Cookies...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Webrequest + Cookies...

    So i've been reading all the posts, and even on msdn about cookies with webrequest.

    I see the cookie, but how do i use it?

    Scenario: I am logging into a website, and it saved the cookie..but each time i tell it to navigate somewhere else..says im not logged in... this would be because of the cookie.

    Can anyone give me a quick n easy example of how to implement the cookie?

  2. #2
    Addicted Member DramaQueen's Avatar
    Join Date
    Mar 2010
    Posts
    187

    Re: Webrequest + Cookies...

    Code:
    Dim Cookies As New CookieContainer
            Cookies.Add(New Cookie("testcookie", "testvalue"))
            Dim request As HttpWebRequest = CType(WebRequest.Create("http://www.google.fi/"), HttpWebRequest)
            request.CookieContainer = Cookies

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: Webrequest + Cookies...

    ok, i got the dim cookies as cookiecontainer part.

    wouldnt the cookies.add come from the website itself?

  4. #4
    Addicted Member DramaQueen's Avatar
    Join Date
    Mar 2010
    Posts
    187

    Re: Webrequest + Cookies...

    Nope. If you're using webrequests you need to do everything yourself that a browser would normally do. In this case you need to parse the cookies from the response you get, add them into your cookies, and when requesting again set your request.CookieContainer = cookies.

    EDIT: I think the cookies are already parsed in the response you get, so this should be a fairly simple task.
    Last edited by DramaQueen; Mar 30th, 2010 at 02:12 AM.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: Webrequest + Cookies...

    I was playing with some commands and saw we had the cookie saved...

    as it showed up...just didnt know how to...reuse it.

  6. #6
    Addicted Member DramaQueen's Avatar
    Join Date
    Mar 2010
    Posts
    187

    Re: Webrequest + Cookies...

    Quote Originally Posted by TCarter View Post
    I was playing with some commands and saw we had the cookie saved...

    as it showed up...just didnt know how to...reuse it.
    Well did you get it figured out now? If so, mark the thread as resolved

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: Webrequest + Cookies...

    havnt had time to play with it to be honest, but i will if this works.

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