Very Simple
Code:Imports System.Web Imports System.Net Imports System.IOFunction GetStringBetweenCode:Public Sub YahooLogin(ByVal Username As String, ByVal Password As String) Dim strU As String, strChallenge As String, strPD As String Dim PageSource As String = String.Empty Dim CC As CookieContainer = New CookieContainer() Dim Request As HttpWebRequest = HttpWebRequest.Create("https://login.yahoo.com/config/login?.src=fpctx&.intl=us&.done=http%3A%2F%2Fwww.yahoo.com%2F") 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, Chr(34), "'") strU = GetStringBetween(PageSource, "<input type='hidden' name='.u' value='", "'>") strChallenge = GetStringBetween(PageSource, "<input type='hidden' name='.challenge' value='", "'>") strPD = GetStringBetween(PageSource, "<input type='hidden' name='.pd' value='", "'>") ' .tries=1&.src=fpctx&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.bypass=&.partner=&.u=3u59m6h5res4f&.v=0&.challenge=eS_RUBoq7DSsTyn1GL9RNQznulvj&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.chkP=Y&.done=http://www.yahoo.com/&.pd=fpctx_ver=0&c=&ivt=&sg=&login=EMAIL@yahoo.com&passwd=PASSWORD&.save=Sign In ' .tries=1&.src=fpctx&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.bypass=&.partner=&.u=3u59m6h5res4f&.v=0&.challenge=eS_RUBoq7DSsTyn1GL9RNQznulvj&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.chkP=Y&.done=http%3A%2F%2Fwww.yahoo.com%2F&.pd=fpctx_ver%3D0%26c%3D%26ivt%3D%26sg%3D&login=EMAIL%40yahoo.com&passwd=PASSWORD&.save=Sign+In Dim strPostData As String = ".tries=1&.src=fpctx&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.bypass=&.partner=&.u=" & _ strU & "&.v=0&.challenge=eS_" & _ strChallenge & "&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.chkP=Y&.done=http%3A%2F%2Fwww.yahoo.com%2F&.pd=" & _ System.Web.HttpUtility.UrlEncode(strPD) & "&login=" & _ System.Web.HttpUtility.UrlEncode(Username) & "&passwd=" & _ Password & "&.save=Sign+In" Request = HttpWebRequest.Create("https://login.yahoo.com/config/login?") Request.Referer = "https://login.yahoo.com/config/login?.src=fpctx&.intl=us&.done=http%3A%2F%2Fwww.yahoo.com%2F" 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() TextBox1.Text = PageSource If (InStr(1, PageSource, ">click here</a> to continue.", CompareMethod.Text) <> 0) Then MsgBox("Login Success!") ElseIf (InStr(1, PageSource, "<title>Sign in to Yahoo!</title>", CompareMethod.Text) <> 0) Then MsgBox("Failed To Login") End If End Sub
Code:Public Function GetStringBetween(ByVal InputText As String, ByVal StartText As String, ByVal EndText As String, Optional ByVal StartPosition As Object = 1) As String Dim lnTextStart As Integer Dim lnTextEnd As Integer 'UPGRADE_WARNING: Couldn't resolve default property of object StartPosition. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"' lnTextStart = InStr(StartPosition, InputText, StartText, CompareMethod.Text) + Len(StartText) lnTextEnd = InStr(lnTextStart, InputText, EndText, CompareMethod.Text) 'UPGRADE_WARNING: Couldn't resolve default property of object StartPosition. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"' If lnTextStart >= (StartPosition + Len(StartText)) And lnTextEnd > lnTextStart Then GetStringBetween = Mid(InputText, lnTextStart, lnTextEnd - lnTextStart) Else GetStringBetween = "" End If End Function
Results 1 to 4 of 4
- 03 Apr. 2010 06:32pm #1
[VB.NET]Yahoo! Login(HttpWebRequest+HttpWebResponse)
Last edited by Blazer; 08 Apr. 2010 at 12:04am.
- 07 Apr. 2010 05:37pm #2
Thanks for this Blazer!
- 09 Dec. 2010 03:56am #3
how do i use this I'm kinda confused lol I'm new to this
- 10 Dec. 2010 02:02am #4