This question is a follow up to my previous question about getting the HTML from an ASPX page. I decided to try using the webclient object, but the problem is that I get the login page’s HTML because login is required. I tried ‘logging in’ using the webclient object:
WebClient ww = new WebClient(); ww.DownloadString('Login.aspx?UserName=&Password='); string html = ww.DownloadString('Internal.aspx');
But I still get the login page all the time. I know that the username info is not stored in a cookie. I must be doing something wrong or leaving out an important part. Does anyone know what it could be?
Just pass valid login parameters to a given URI. Should help you out.
If you don’t have login information you shouldn’t be trying to circumvent it.
public static string HttpPost( string URI, string Parameters ) { System.Net.WebRequest req = System.Net.WebRequest.Create( URI ); req.ContentType = 'application/x-www-form-urlencoded'; req.Method = 'POST'; byte[] bytes = System.Text.Encoding.ASCII.GetBytes( Parameters ); req.ContentLength = bytes.Length; System.IO.Stream os = req.GetRequestStream(); os.Write( bytes, 0, bytes.Length ); os.Close(); System.Net.WebResponse resp = req.GetResponse(); if ( resp == null ) return null; System.IO.StreamReader sr = new System.IO.StreamReader( resp.GetResponseStream() ); return sr.ReadToEnd().Trim(); }