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: 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)
        response = request.GetResponse()

        For Each tempCookie As Net.Cookie In response.Cookies

        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!

This article has been dead for over six months. Start a new discussion instead.