asp.net - Getting HTML from a page behind a login -
this question follow previous question getting html aspx page. decided try using webclient object, problem login page's html because login required. tried "logging in" using webclient object:
webclient ww = new webclient(); ww.downloadstring("login.aspx?username=&password="); string html = ww.downloadstring("internal.aspx");
but still login page time. know username info not stored in cookie. must doing wrong or leaving out important part. know be?
just pass valid login parameters given uri. should out.
if don't have login information shouldn't trying 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(); }
Comments
Post a Comment