Facebook HttpWebRequest LOGIN

TMTakas

Member
Joined
Feb 6, 2013
Messages
15
Programming Experience
Beginner
Hi vbdotnetforums ,
i want to make a program that can login to facebook , i used the code below , but when i want to display the Response , the Response is not the facebook index page :

VB.NET:
    Dim logincookie As CookieContainer


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim postData As String = "lsd=AVqhyR-X&email=" & textbox1.text & "&pass=" & textbox2.text & "&default_persistent=0&timezone=-120&lgnrnd=170347_eJAP&lgnjs=1412813029&locale=en_US&qsstamp=W1tbNSwxOCwzNiw2Myw2Nyw3NywxMjMsMTgwLDE4OSwyMjQsMjU0LDI2NCwyNjUsMjY4LDI4MywzMDksMzE2LDMxOCwzMjQsMzQyLDM2Miw0MDgsNDM1LDQ0Miw0NTUsNDc0LDQ3OSw0ODgsNTA4LDUxMyw1MTgsNTI1LDUyOCw1NDMsNTQ0LDU1Miw1ODYsNjA2LDYwOCw2MTgsNjgwLDc1Nl1dLCJBWmxxOVhNMU9xbVg2OHNiV291T2VxVG5yalZRNjVsYVM4TzZ6Zk5XZ05CVUpYMlVFUXpGeVk4cmxmRUN3YXlFOGdhRGhnYkRVV0FQSzlRZkUta1Q4RVNtMkY0dUhwUXR2TDZ2bDZKUGtNc2ZkNzlyUXBDd1dxOFhzUFFnSEtEVHNGakJKWXd4S3lKcTJyY3pGTWxRXzZVaU5qUE9IdzQxNDhyc2dtRHBleS16Z0hKVDAteVhTd2NiVHprdnI2Q21sd0d0V0p4cmxoZXQ0Z3gzbUFNcl95WXdSNWtjN05jaUNHN0VuWDdQWHFVb0tnIl0%3D"

        Dim tempCookies As New CookieContainer
        Dim encoding As New UTF8Encoding
        Dim byteData As Byte() = encoding.GetBytes(postData)


        Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://www.facebook.com/login.php?login_attempt=1"), HttpWebRequest)
        postReq.Method = "POST"
        postReq.KeepAlive = True
        postReq.CookieContainer = tempCookies
        postReq.ContentType = "application/x-www-form-urlencoded"
        postReq.Referer = "https://www.facebook.com/login.php?login_attempt=1"
        postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
        postReq.ContentLength = byteData.Length


        Dim postreqstream As Stream = postReq.GetRequestStream()
        postreqstream.Write(byteData, 0, byteData.Length)
        postreqstream.Close()
        Dim postresponse As HttpWebResponse


        postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
        tempCookies.Add(postresponse.Cookies)
        logincookie = tempCookies
        Dim postreqreader As New StreamReader(postresponse.GetResponseStream())


        Dim thepage As String = postreqreader.ReadToEnd




        Dim request As HttpWebRequest = DirectCast(WebRequest.Create("https://m.facebook.com"), HttpWebRequest)
        request.CookieContainer = logincookie
        Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
        Dim reader As New StreamReader(response.GetResponseStream())
        Dim theusercp As String = reader.ReadToEnd


        WebBrowser1.DocumentText = theusercp

    End Sub
 
Back
Top