Wentu Posted February 21, 2004 Posted February 21, 2004 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 http://www.AddressOfThePageIWantToRead.asp . In the login page there is a form whose action is http://www.AddressOfThePageIWantToRead.asp and method = POST . The names of the textboxes where i write are "username" and "password". I'd like to be able to give my username and pwd and write in a string (lcHtml) the content of http://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 Quote
HJB417 Posted February 23, 2004 Posted February 23, 2004 I would use mozilla with live http headers and compare the data in the headers with what you're sending. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.