[RESOLVED] HTTP Webrequest post (Login to YAhooMail)
I finally logged in to yahoomail using httpwebrequest.
my problem now is how I am going to put a messagebox saying my log in is successful or not.
for now im trying to login using a correct username and pass.
Hope someone can help me about it.
Here's my code so far.
Code:
Imports System.IO
Imports System.Net
Imports System.Text
Public Class Form1
Dim loginCoockie As New CookieContainer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim uName As String = TextBox1.Text
Dim pWord As String = TextBox2.Text
Label1.Text = "Trying to Log In"
Dim postData As String = ".tries=1&.src=ym&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.bypass=&.partner=&.u=7jebrpt78q79h&.v=0&.challenge=a5PSc8KUgQ7.sU0VVUE9JsdHOosB&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.chkP=Y&.done=http%3A%2F%2Fmail.yahoo.com&.pd=ym_ver%3D0%26c%3D%26ivt%3D%26sg%3D&.ws=1&.cp=0&pad=5&aad=6&login=" & uName & "&passwd=" & pWord & "&.save=&passwd_raw="
Dim tempCookies As New CookieContainer
Dim encoding As New UTF8Encoding
Dim byteData As Byte() = encoding.GetBytes(postData)
Dim postRequest As HttpWebRequest = DirectCast(WebRequest.Create("https://login.yahoo.com/config/login"), HttpWebRequest)
postRequest.Method = "POST"
postRequest.KeepAlive = True
postRequest.CookieContainer = tempCookies
postRequest.ContentType = "application/x-www-form-urlencoded"
postRequest.Referer = "https://login.yahoo.com/config/login"
postRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0a2) Gecko/20110613 Firefox/6.0a2"
postRequest.ContentLength = byteData.Length
Dim postReqStream As Stream = postRequest.GetRequestStream
postReqStream.Write(byteData, 0, byteData.Length)
postReqStream.Close()
Dim postResponse As HttpWebResponse
postResponse = DirectCast(postRequest.GetResponse(), HttpWebResponse)
tempCookies.Add(postResponse.Cookies)
loginCoockie = tempCookies
Dim postReqReader As New StreamReader(postResponse.GetResponseStream())
End Sub
Thanks.
Re: HTTP Webrequest post (Login to YAhooMail)
Hello,
In order to know if it was successful to need to inspect the response that you are getting back from the server. This may involve simply looking at the Response Code, or you may need to inspect the actual HTML of the response and look for a certain string to indicate that it was successful.
Gary
Re: HTTP Webrequest post (Login to YAhooMail)
Add this code after
Code:
Dim thepage As String = postreqreader.ReadToEnd
If thepage.Contains("Please try again using your full Yahoo! ID.") = True Then '
MsgBox("Incorrect Username/password combination", 0, "Login error!")
Else
MsgBox("Logged in", 0, "Success!")
End If
Code:
Dim postReqReader As New StreamReader(postResponse.GetResponseStream())
Re: HTTP Webrequest post (Login to YAhooMail)
sorry for my first post. change the
Please try again using your full Yahoo! ID.
to
"status" : "error"
i just tested it.
1 Attachment(s)
Re: HTTP Webrequest post (Login to YAhooMail)
Im trying to use Regex but i dont know how to implement it in codes.
Here's my source code.
Re: HTTP Webrequest post (Login to YAhooMail)
Quote:
Originally Posted by
aronquiray
sorry for my first post. change the
Please try again using your full Yahoo! ID.
to
"status" : "error"
i just tested it.
You Mean This?
Quote:
Dim postReqReader As New StreamReader(postResponse.GetResponseStream())
Dim thepage As String = postreqreader.ReadToEnd
If thepage.Contains("status : error") = True Then
MsgBox("Incorrect Username/password combination", 0, "Login error!")
Else
MsgBox("Logged in", 0, "Success!")
End If
Sorry I am really new to this...
Re: HTTP Webrequest post (Login to YAhooMail)
@aronquiray
I get it and Its working... :D
Thank you very much!!!
Re: HTTP Webrequest post (Login to YAhooMail)
On the note of using Regex, if you are trying to parse the returned HTML, you might want to think about using the HtmlAgilityPack:
http://htmlagilitypack.codeplex.com/
Which does some of the "heavy lifting" for you.
Gary