Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27333

VS 2010 Http Web Request - logging in

$
0
0
Hello all I have a program that I want to use to login into a website called Tumblr.

I have got this code so far but when I try to login I always get a failed login.

Am I missing something?

Code:

Imports System.Net
Imports System.Text
Imports System.IO


Public Class tl

    Private Cookies As New CookieContainer()
    Public LoggedInCookies As New CookieContainer

    Private Token_Session As String


    Public Function Login(ByVal Email As String, ByVal Pass As String) As Boolean

        If Email.Contains("@") = False Then
            MessageBox.Show("Please enter a valid e-mail address!", "Error - Invalid E-mail", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return False
            Exit Function
        End If

        Dim URL As String = "https://www.tumblr.com/login"

        Dim GETHTTP As HttpWebRequest = DirectCast(HttpWebRequest.Create(URL), HttpWebRequest)

        With GETHTTP
            .KeepAlive = False
            .Method = "GET"
            .Pipelined = True
            .Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
            .UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0"
            .Referer = URL
            .Host = "www.tumblr.com"
            .CookieContainer = New CookieContainer()
            Cookies = .CookieContainer
        End With

        Dim GETResponse As HttpWebResponse = DirectCast(GETHTTP.GetResponse(), HttpWebResponse)
        Dim GETReader As StreamReader = New StreamReader(GETResponse.GetResponseStream())

        Dim GETHTML As String = String.Empty

        Do Until GETReader.EndOfStream
            GETHTML += GETReader.ReadLine
        Loop

        Dim ParseFinish As String = ChrW(34)

        If GETHTML.Contains("tumblr") = True Then

            'Token_Session = Split(Split(GETHTML, "tumblr")(1), ParseFinish)(0)


            ' Send our POST Login request

            Dim PostData As String = "user%5Bemail%5D=" & Email & "&user%5Bpassword%5D=" & Pass & "&tumblelog%5Bname%5D=&user%5Bage%5D=&recaptcha_public_key=6Lf4osISAAAAAJHn-CxSkM9YFNbirusAOEmxqMlZ&recaptcha_response_field=&hk=703563000651c0099e0e00ad8ec31162e233d876+1356395520+5a8e5bd0ea9c5e183360916efd4efcc70f07d316&form_key=%211231356395521%7CDOOoVFrQIKnbmrdnO5fqBtEEpg"

            Dim Bytes() As Byte = UTF8Encoding.ASCII.GetBytes(PostData)

            Dim POSTURL As String = "https://www.tumblr.com/login"

            Dim POSTHTTP As HttpWebRequest = DirectCast(HttpWebRequest.Create(POSTURL), HttpWebRequest)

            With POSTHTTP
                .KeepAlive = False
                .Method = "POST"
                .Pipelined = True
                .UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1"
                .Referer = URL
                .CookieContainer = Cookies
                .ContentType = "application/x-www-form-urlencoded"
                .ContentLength = Bytes.Length
            End With

            Dim POSTWriter As Stream = POSTHTTP.GetRequestStream()
            POSTWriter.Write(Bytes, 0, Bytes.Length)
            POSTWriter.Close()

            Dim POSTResponse As HttpWebResponse = DirectCast(POSTHTTP.GetResponse(), HttpWebResponse)
            Dim POSTReader As StreamReader = New StreamReader(POSTResponse.GetResponseStream())

            Dim POSTHTML As String = String.Empty

            Do Until POSTReader.EndOfStream
                POSTHTML += POSTReader.ReadLine
            Loop

            POSTReader.Close()
            POSTResponse.Close()

            If POSTHTML.Contains(">Log out</a>") = True Then

                LoggedInCookies = Cookies

                Return True

            Else

                Return False

            End If

        Else


            MsgBox("Unable to create session.", MsgBoxStyle.Critical, "Error - Session wasn't able to be created.")

            Return False

            Exit Function

        End If

    End Function



End Class


Viewing all articles
Browse latest Browse all 27333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>