FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

[VB.NET] Open a page using IE cookies

 


fromegame
Hiya,

I have a few member-only-pages on my website. I know how I can access those sites with VB, but how can I access them using cookies. So that the program itself, creates the cookies when he needs to. Like in IE Smile

It's a bit like this (but then in VB not python):
I want to do this: http://www.thescripts.com/forum/thread24677.html

Thanks in advance Wink


Last edited by fromegame on Sun May 20, 2007 3:44 pm; edited 1 time in total
fromegame
I got this now:

When logging in:

Code:

        Dim address As New Uri("http://www.frome.frih.net/login.php")
        Dim request As HttpWebRequest = DirectCast(WebRequest.Create(address), HttpWebRequest)
        Dim response As HttpWebResponse = Nothing
        Dim data As System.Text.StringBuilder
        Dim byteData() As Byte
        Dim postStream As IO.Stream = Nothing
        Dim reader As IO.StreamReader
        request.Method = "POST"
        request.ContentType = "application/x-www-form-urlencoded"
        request.CookieContainer = New CookieContainer()
        data = New System.Text.StringBuilder()
        data.Append("login=" & txtUsername.Text)
        data.Append("&password=" & txtPassword.Text)
        byteData = System.Text.UTF8Encoding.UTF8.GetBytes(data.ToString())
        request.ContentLength = byteData.Length
        postStream = request.GetRequestStream()
        postStream.Write(byteData, 0, byteData.Length)
        response = DirectCast(request.GetResponse(), HttpWebResponse)
        reader = New IO.StreamReader(response.GetResponseStream())
        Dim myAnswer As String = reader.ReadToEnd()
        Cookie1 = response.Cookies.Item(0)
        Cookie2 = response.Cookies.Item(1)

This should give 2 cookies, and I store them in Cookie1 and Cookie2

When requesting a member-only page:

Code:

                Dim address As New Uri("http://www.frome.frih.net/mmb/index.php")
                Dim request As HttpWebRequest = DirectCast(WebRequest.Create(address), HttpWebRequest)
                Dim response As HttpWebResponse = Nothing
                Dim reader As IO.StreamReader
                request.CookieContainer = New CookieContainer()
                request.CookieContainer.Add(Cookie1)
                request.CookieContainer.Add(Cookie2)
                response = DirectCast(request.GetResponse(), HttpWebResponse)
                reader = New IO.StreamReader(response.GetResponseStream())
                Dim myAnswer As String = reader.ReadToEnd()

                MsgBox(myAnswer)


Can anyone tell me, why it still says cookies aren't enabled?
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.