FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free 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
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?
Related topics
Why use IE?
visual basic.net
VB.NET school
VB 6 and vb.net tutorials
phpbb forum giving blank page in IE
VB.NET and SQL Server
VB.NET learning
How do i password protect a web page using html
Need vb.net or Flash ActionScript Help!
VB.Net Or C#
A confusion with C# and VB.NET...
OMG! vb.net without connection to server option?
How change the background-image of a page using CSS?
vb.net class as property of another class - FIXED
Reply to topic    Frihost Forum Index -> Scripting -> Others

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