Hello everyone,
I'm attempting to log into Hotmail using Web Requests, but I'm having a little trouble. It seems I can log in fine, but when I try to access Hotmail, it takes back to a login page with puts me in a constant loop. The important code can be found below.
request = HttpWebRequest.Create(url)
request.CookieContainer = cookies
If proxycheck.Checked = True Then
request.Timeout = 7500
request.ReadWriteTimeout = 7500
End If
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
request.Referer = referer
request.KeepAlive = True
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "en-US")
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.52.7 (KHTML, like Gecko) Version/5.1.2 Safari/534.52.7"
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate")
'request.AutomaticDecompression = DecompressionMethods.GZip
If proxycheck.Checked = True Then
request.Proxy = New WebProxy(IP, True)
End If
Dim response As HttpWebResponse = request.GetResponse()
Dim remoteStream As Stream
Dim readStream As StreamReader
remoteStream = response.GetResponseStream
readStream = New StreamReader(remoteStream)
theresponse = readStream.ReadToEnd
readStream.Close()
If theresponse.Contains("https://login.live.com/ppsecure/post.srf") Then
referer = request.Address.AbsoluteUri
url = "https://login.live.com/ppsecure/post.srf" & GetStringBetween(theresponse, "https://login.live.com/ppsecure/post.srf", "'")
'url = url.Replace("%2fm%2f", "%2fm")
postdata = "PPFT=" & GetStringBetween(theresponse, "PPFT"" id=""i0327"" value=""", """") & "&login=" & parts(0) & "&passwd=" & parts(1) & "&LoginOptions=3&NewUser=1&PPSX=Passpor&type=11&i3=6115&m1=1900&m2=1188&m3=0&i12=1&i17=0&i18=__MobileLogin%7C1%2C"
end if
request = HttpWebRequest.Create(url)
request.CookieContainer = cookies
If proxycheck.Checked = True Then
request.Proxy = New WebProxy(IP, True)
End If
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
request.Referer = referer
request.KeepAlive = True
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "en-US")
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.52.7 (KHTML, like Gecko) Version/5.1.2 Safari/534.52.7"
request.ContentType = "application/x-www-form-urlencoded"
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate")
'request.AutomaticDecompression = DecompressionMethods.GZip
request.Headers.Set(HttpRequestHeader.CacheControl, "no-cache")
request.Method = "POST"
If proxycheck.Checked = True Then
request.Timeout = 7500
request.ReadWriteTimeout = 7500
End If
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postdata)
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
response = request.GetResponse()
dataStream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
responsefromserver = reader.ReadToEnd()
reader.Close()
If responsefromserver.Contains("https://login.live.com/ppsecure/post.srf") Then
'MsgBox("Check")
referer = ""
'url = "http://mail.live.com/m/"
url = "http://www.hotmail.com"
GoTo getme
ElseIf responsefromserver.Contains("http://mail.live.com/m/"");}") Then
referer = ""
'url = "http://mail.live.com/m/"
url = "http://www.hotmail.com"
GoTo getme
end if
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
lnTextStart = InStr(StartPosition, InputText, StartText, CompareMethod.Text) + Len(StartText)
lnTextEnd = InStr(lnTextStart, InputText, EndText, CompareMethod.Text)
If lnTextStart >= (StartPosition + Len(StartText)) And lnTextEnd > lnTextStart Then
GetStringBetween = Mid(InputText, lnTextStart, lnTextEnd - lnTextStart)
Else
GetStringBetween = ""
End If
End Function
I know the code above is messy, and I'd be happy to explain any of it if needed. The program gets to the point of...
<script type="text/javascript">function rd(){window.location.replace("http://mail.live.com/m/");}function OnBack(){}</script></head><body onload="javascript:rd();"></body></html>
And attempts to visit the link using a GET request, but that initiates the loop.
Any help would be greatly appreciated.
Thanks in advance,
Resentful