accessing html content using username and pwd

Wentu

Member
Joined
Feb 4, 2004
Messages
7
Hi !

I need to access the HTML content of a page. I know how to do this if the page is public but now i want to access a page that is in a site that requires previous authentication.
What i usually do is going to the login page, write my usernames and password and then submit, and then i have access to www.AddressOfThePageIWantToRead.asp . In the login page there is a form whose action is www.AddressOfThePageIWantToRead.asp and method = POST . The names of the textboxes where i write are "username" and "password".
Id like to be able to give my username and pwd and write in a string (lcHtml) the content of www.AddressOfThePageIWantToRead.asp .
I found something on the net, that is:



Dim lcUrl As String = "http://www.AddressOfThePageIWantToRead.asp"
Dim loHttp As HttpWebRequest = WebRequest.Create(lcUrl)

Dim lcPostData As String = "Username=" & HttpUtility.UrlEncode("MyUsername") & "&Password=" + HttpUtility.UrlEncode("MyPWD")

loHttp.Method = "POST"

Dim lbPostBuffer As Byte() = System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData)

loHttp.ContentLength = lbPostBuffer.Length

Dim loPostData As Stream = loHttp.GetRequestStream()

loPostData.Write(lbPostBuffer, 0, lbPostBuffer.Length)

loPostData.Close()

Dim loWebResponse As HttpWebResponse = loHttp.GetResponse()

Dim enc As Encoding = System.Text.Encoding.GetEncoding(1252)

Dim loResponseStream As StreamReader = New StreamReader(loWebResponse.GetResponseStream(), enc)

Dim lcHtml As String = loResponseStream.ReadToEnd()

loWebResponse.Close()

loResponseStream.Close()




the site is actually responding with a page that says : Username and/or pwd uncorrect.
Of course i know my username and pwd ARE correct. so what could be the problem ? the encoding of UrlEncode ? what else ? what am i missing ?

if the complete answer is too long, at least tell me where to find a good tutorial or illuminating post, please !

thanx !

Wentu
 
Back
Top