Member Avatar for david56connor

Hi, I have been working on this for quite a few hours now and can't seem to find a solution!

My knowledge of VB.Net is quite limited and I'm trying to jump in at the deep end, I'm trying to log in to a website (a game in which I play) that requires a username and password, they must be submitted used the POST method and then I need to be able to view the source of the page to obtain further useful data.

This is what I have at the moment and it isn't working for me.

Function postRequest()
        Dim s As String = ""
        Dim username As String = txtUserName.Text
        Dim pass As String = txtPass.Text
        Dim cookieJar As New CookieContainer()

        Dim postData As String
        postData = "login_username=" + username + "&login_password=" + pass + "&serverid=1"

        Dim request As HttpWebRequest
        Dim response As HttpWebResponse
        request = CType(WebRequest.Create("http://site.com/index.php"), HttpWebRequest)
        request.ContentType = "application/x-www-form-urlencoded"
        request.ContentLength = postData.Length
        request.Method = "POST"
        request.AllowAutoRedirect = False
        request.CookieContainer = cookieJar
        request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11"

        Dim requestStream As Stream = request.GetRequestStream()
        Dim postBytes As Byte() = Encoding.ASCII.GetBytes(postData)
        requestStream.Write(postBytes, 0, postBytes.Length)
        requestStream.Close()
        response = request.GetResponse()

        For Each tempCookie As Net.Cookie In response.Cookies
            cookieJar.Add(tempCookie)
        Next

        Using reader As StreamReader = New StreamReader(response.GetResponseStream())
            s = reader.ReadToEnd()

        End Using

        txtOut.Text = s

        Return response
    End Function

Any help with this would be greatly appreciated!

Member Avatar for david56connor

Anyone have any ideas for this? I'm still struggling to find a solution :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.