I'm trying three different methods for logging into a webmail account. In
Post1() and Post2(), I always get back the login page. Not the page after
logging in. On TryCookies(), I'm not sure. It will run but there are some
other things that need to take place. Any suggestion on what is wrong with
the Post1() and Post2() or how to get TryCookies() going? Any other
guidance is appreciated.
Private Sub TryCookies()
Dim uri As New
Uri("http://netmail.verizon.net/en_US/agent/mo************************@verizon.net&password=so mepassword&jsCapable=1&frames=0&LOCALE=en_US&VARIA NT=")
Dim cookieUri As New Uri("http://netmail.verizon.net")
Dim request As System.Net.HttpWebRequest
Dim response As System.Net.HttpWebResponse
request = CType(System.Net.WebRequest.Create(uri),
System.Net.HttpWebRequest)
request.CookieContainer = New System.Net.CookieContainer
request.CookieContainer.SetCookies(cookieUri,
"ABCD=G7789Ooqdowjkc7rrFA28r5hp0f78e")
'Me.rtxtShowWebpage.Text = response.ContentEncoding()
End Sub
Private Sub Post2()
Dim encoding As New ASCIIEncoding
' Use the appropriate HTML field names to stuff into the post header
Dim PostData As String =
"?u****************@verizon.net&password=somepassw ord&jsCapable=1&frames=0&LOCALE=en_US&VARIANT="
Dim Data() As Byte = encoding.GetBytes(PostData)
'Dim Cookies As New CookieContainer
' Initialise the request
Dim LoginReq As System.Net.HttpWebRequest =
System.Net.WebRequest.Create("http://netmail.verizon.net/en_US/agent/moblogin")
With LoginReq
.KeepAlive = False
.Method = "POST"
' Note: if the page uses a redirect if will fail (see below)
.AllowAutoRedirect = False
.ContentType = "application/x-www-form-urlencoded"
.ContentLength = Data.Length
End With
' Add the POST data
Dim SendReq As Stream = LoginReq.GetRequestStream
SendReq.Write(Data, 0, Data.Length)
SendReq.Close()
' Obtain the response
Dim LoginRes As System.Net.HttpWebResponse = LoginReq.GetResponse()
Dim sReader As StreamReader = New
StreamReader(LoginRes.GetResponseStream)
Dim HTML As String = sReader.ReadToEnd
Me.rtxtShowWebpage.Text = HTML
End Sub
Private Sub Post1()
Dim wrq As System.Net.WebRequest = _
System.Net.WebRequest.Create("http://netmail.verizon.net/en_US/agent/moblogin")
wrq.Credentials = New System.Net.NetworkCredential("us**@verizon.net",
"somepassword")
Dim wrp As System.Net.WebResponse = wrq.GetResponse()
Dim sr As New StreamReader(wrp.GetResponseStream())
'MessageBox.Show(sr.ReadToEnd())
Me.rtxtShowWebpage.Text = sr.ReadToEnd
sr.Close()
wrp.Close()
Dim myclient As System.Net.WebClient = New System.Net.WebClient
Dim bufData As Byte()
Dim firstLevelbufData As String
bufData = myclient.DownloadData("http://www.microsoft.com")
' got the bufData now convert it into string format
' firstLevelbufData is a string variable
firstLevelbufData = Encoding.Default.GetString(bufData)
End Sub
Thanks,
Brett