Results 1 to 6 of 6
-
20th Jun 2010, 02:50 PM #1OPBanned
[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
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
-
24th Jun 2010, 10:13 PM #2Member
-
24th Jun 2010, 10:41 PM #3Respected Developer
Stealing code and making it look as if it's yours is lame. (@ rapid-ddldotcom)
-
28th Jun 2010, 09:39 AM #4MemberWebsite's:
Elite.SO Defendos.com Motionite.comsqueakers are lame. ( @ hassanahmad )
anyway this could be useful for some members here. (not for me. l0calh0st(L)lua )
-
28th Jun 2010, 11:05 AM #5Respected MemberWebsite's:
nooky.usAll what hassan produces, is a 404 error.
-
29th Jun 2010, 11:50 AM #6MemberAll what hassan produces, is a 404 error.
squeakers are lame. ( @ hassanahmad )
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Accessing Website Stats without logging into cPanel
By Areon in forum Server ManagementReplies: 0Last Post: 3rd Mar 2014, 01:23 PM -
need a code in php - show all posts from a irc channel on website
By sloddl in forum Web Development AreaReplies: 5Last Post: 30th Jun 2012, 05:47 PM -
[Hiring] Someone to code a website
By Spetsnaz in forum ServicesReplies: 0Last Post: 20th May 2012, 03:01 PM -
[Hiring] Need a coder to code a cutom website
By downloadsmasti in forum Completed TransactionsReplies: 3Last Post: 16th Oct 2011, 11:41 AM -
Need help to add a code in my website
By Divvy in forum Webmaster DiscussionReplies: 1Last Post: 15th Mar 2011, 02:15 AM
themaRegister - register to forums...
Version 3.54 released. Open older version (or...