Activity Stream
48,167 MEMBERS
6765 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 6 of 6
  1.     
    #1
    Banned

    Smile [Vb.Net] ? Example code for logging into a website programmatically

    The example below uses HttpWebRequest and HttpWebResponse classes to log in to Facebook.

    Code: 
    Dim cookieJar As New Net.CookieContainer()
            Dim request As Net.HttpWebRequest
            Dim response As Net.HttpWebResponse
            Dim strURL As String
    
            Try
                'Get Cookies
                strURL = "https://login.facebook.com/login.php"
                request = Net.HttpWebRequest.Create(strURL)
                request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"
                request.Method = "GET"
                request.CookieContainer = cookieJar
                response = request.GetResponse()
    
                For Each tempCookie As Net.Cookie In response.Cookies
                    cookieJar.Add(tempCookie)
                Next
    
                'Send the post data now
                request = Net.HttpWebRequest.Create(strURL)
                request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"
                request.Method = "POST"
                request.AllowAutoRedirect = True
                request.CookieContainer = cookieJar
    
                Dim writer As StreamWriter = New StreamWriter(request.GetRequestStream())
                writer.Write("email=username&pass=password")
                writer.Close()
                response = request.GetResponse()
    
                'Get the data from the page
                Dim stream As StreamReader = New StreamReader(response.GetResponseStream())
                Dim data As String = stream.ReadToEnd()
                response.Close()
    
                If data.Contains("<title>Facebook") = True Then
                    'LOGGED IN SUCCESSFULLY
                End If
    
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    
    
    Now, here is some explanation.
                 For Each tempCookie As Net.Cookie In response.Cookies
                    cookieJar.Add(tempCookie)
                Next
     The block of code above gets all the cookies and stores it in a  collection, which are returned upon visiting the webpage: https://login.facebook.com/login.php.  These cookies are important because they must be passed back to the  webpage when you are going to login.
                 Dim writer As StreamWriter = New StreamWriter(request.GetRequestStream())
                writer.Write("email=username&pass=password")
                writer.Close()
     The code above creates a StreamWriter class and writes the post data to  it. You can pass any data here to the website in name=value&name=value  format.
                 Dim stream As StreamReader = New StreamReader(response.GetResponseStream())
                Dim data As String = stream.ReadToEnd()
                response.Close()
    
                If data.Contains("<title>Facebook") = True Then
                    'LOGGED IN SUCCESSFULLY
                End If
    ^ Finally, it gets the source code of the webpage returned which is the homepage of your account (i.e home.php), and checks if you are logged in successfully or not.
    I hope this code will help you to save some time. If you find it useful then do let me know via your comments.
    rapid-ddldotcom Reviewed by rapid-ddldotcom on . [Vb.Net] ? Example code for logging into a website programmatically The example below uses HttpWebRequest and HttpWebResponse classes to log in to Facebook. Dim cookieJar As New Net.CookieContainer() Dim request As Net.HttpWebRequest Dim response As Net.HttpWebResponse Dim strURL As String Try 'Get Cookies strURL = "https://login.facebook.com/login.php" Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Member

  4.     
    #3
    Respected Developer
    Stealing code and making it look as if it's yours is lame. (@ rapid-ddldotcom)

  5.     
    #4
    Member
    Website's:
    Elite.SO Defendos.com Motionite.com
    squeakers are lame. ( @ hassanahmad )
    anyway this could be useful for some members here. (not for me. l0calh0st(L)lua )

    Defendos BETA3 Released! Thread - Official Website

  6.     
    #5
    Respected Member
    Website's:
    nooky.us
    All what hassan produces, is a 404 error.

  7.     
    #6
    Member
    All what hassan produces, is a 404 error.
    I changed the title of the post, that is why the link stopped working. Link edited now!

    squeakers are lame. ( @ hassanahmad )
    Sorry, I didn't get you. What do you mean?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Accessing Website Stats without logging into cPanel
    By Areon in forum Server Management
    Replies: 0
    Last Post: 3rd Mar 2014, 01:23 PM
  2. Replies: 5
    Last Post: 30th Jun 2012, 05:47 PM
  3. [Hiring] Someone to code a website
    By Spetsnaz in forum Services
    Replies: 0
    Last Post: 20th May 2012, 03:01 PM
  4. [Hiring] Need a coder to code a cutom website
    By downloadsmasti in forum Completed Transactions
    Replies: 3
    Last Post: 16th Oct 2011, 11:41 AM
  5. Need help to add a code in my website
    By Divvy in forum Webmaster Discussion
    Replies: 1
    Last Post: 15th Mar 2011, 02:15 AM

Tags for this Thread

BE SOCIAL