1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[HELP] Webbrowser cookies to webrequest cookiecontainer

Discussion in 'Visual Basic .NET' started by carlx, Apr 18, 2013.

  1. carlx

    carlx Registered Member

    Joined:
    Dec 28, 2008
    Messages:
    95
    Likes Received:
    88
    Hi,

    I was wondering if anybody had any advice or had faced this problem themselves.

    I am logging into a website via a webbrowser in order to grab the relevent cookies that i want (Cant do webrequest because it uses ajax and javascript to login)

    Once it is logged in i want to get the cookies it sets to allow me to webrequest some further

    I cant seem to set the cookiecontainer to be the cookies from the webbrowser.

    Any advice?
     
  2. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,880
    Likes Received:
    1,932
    Something like this should do it:
    Code:
    Dim cookies as new cookiecontainer
    Dim WebBrowserCookies = newBrowser.Document.Cookie
    Dim SplitCookies() as string = split(WebBrowserCookies, "; ")
    For each tmpcookie as string in SplitCookies
    	if tmpcookie = nothing then continue for
    	cookies.Add(New Uri("http://site.com"), New Cookie(Split(tmpcookie,"=")(0), Split(tmpcookie,"=")(1)))
    End For
    Edit: Forgot to note, if the cookie could possibly contain an = symbol simply join the rest of the array values after 0 to create the true cookie value.
     
    • Thanks Thanks x 2
    Last edited: Apr 18, 2013