I wrote this code a few hours ago, Very Simple, an Very easy for people that know VB.NET.
Code:Imports System.Net Imports System.Web Imports System.IO Public Function Login(ByVal Username As String, _ ByVal Password As String) As Boolean Dim strToken As String, strSID As String, strRedirect As String Dim PageSource As String = String.Empty Dim CC As CookieContainer = New CookieContainer() Dim Request As HttpWebRequest = HttpWebRequest.Create("http://www.gaiaonline.com/auth") Request.Method = WebRequestMethods.Http.Get Request.KeepAlive = True Request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2 (.NET CLR 4.0.20506)" Request.CookieContainer = CC Dim Response As HttpWebResponse = Request.GetResponse() Dim Stream As New StreamReader(Response.GetResponseStream()) PageSource = Stream.ReadToEnd() Response.Close() PageSource = Replace(PageSource, """", "'") strToken = GetStringBetween(PageSource, "<input type='hidden' name='token' value='", "' />") strSID = GetStringBetween(PageSource, "<input type='hidden' name='sid' value='", "' />") strRedirect = GetStringBetween(PageSource, "<input type='hidden' name='redirect' value='", "' />") Dim strPostData As String = "token=" & _ strToken & "&sid=" & _ strSID & "&redirect=" & _ System.Web.HttpUtility.UrlEncode(strRedirect) & "&username=" & _ System.Web.HttpUtility.UrlEncode(Username) & "&password=" & _ Password & "&chap=" Request = HttpWebRequest.Create("http://www.gaiaonline.com/auth/login/") Request.Referer = "http://www.gaiaonline.com/auth" Request.KeepAlive = True Request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2 (.NET CLR 4.0.20506)" Request.CookieContainer = CC Request.Method = WebRequestMethods.Http.Post Request.ContentType = "application/x-www-form-urlencoded" Request.ContentLength = strPostData.Length Dim writer As New StreamWriter(Request.GetRequestStream) writer.Write(strPostData) writer.Close() Response = Request.GetResponse() Dim reader As New StreamReader(Response.GetResponseStream()) PageSource = reader.ReadToEnd() Response.Close() If (InStr(1, PageSource, "<title>Welcome to Gaia | Gaia Online</title>", CompareMethod.Text) <> 0) Then Login = True Else Login = False End If End Function
Results 1 to 12 of 12
Threaded View
- 03 Apr. 2010 07:17am #1
[VB.NET]Gaia Login(HttpWebRequest+HttpWebResponse)