A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

[VB.NET]Gaia Login(HttpWebRequest+HttpWebResponse)

2.5k views · started by Blazer ·
#1
[VB.NET]Gaia Login(HttpWebRequest+HttpWebResponse)
I wrote this code a few hours ago, Very Simple, an Very easy for people that know VB.NET.


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
#2
Very nice Blazer... Its simple and effective.

Although most people prefer to use HTTP Wrappers.
#3
Bman wrote:
Very nice Blazer... Its simple and effective.

Although most people prefer to use HTTP Wrappers.

I now, but with this you can have multiple cookie sessions.
#4
Ahh, I didnt see this :O

Thanks for telling me.
#5
Works great, used it in my shitty public program and currently using it in my Arena voter.

E: If you're still active, think you could make a logout function?
#6
How do i use it with the httprequest ect. please
#7
To use the function for the login, it's:
If Login(txtUsername, txtPassword) = True then
msgbox("Logged in!")
Elseif Login(txtUsername, txtPassword) = False then
msgbox("Login Failed!")
End if


If you're asking how to use the HTTPWebRequest to do things, I'll make a tutorial :B
#8
TEMPTii wrote:
To use the function for the login, it's:
If Login(txtUsername, txtPassword) = True then
msgbox("Logged in!")
Elseif Login(txtUsername, txtPassword) = False then
msgbox("Login Failed!")
End if


If you're asking how to use the HTTPWebRequest to do things, I'll make a tutorial :B


oh ok cool ill be ready to see it hehe thanks xD
#9
Awesome. saves me time. ;P +1 for the time saver1111!
#10
It's messy. It helps if you like VB.net though. I suggest making your own wrappers using the Requests and stuff. It would be faster.
#11
Wow you know how to make a wrapper ?
#12
Making a wrapper is simply making a class and turning this into functions. I'll do it :B