Results 1 to 8 of 8

Thread: Service in vb.net that needs to login to an asp page

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Location
    NH
    Posts
    90

    Service in vb.net that needs to login to an asp page

    I am writing a service that needs to login into a .asp page This is what I was attempting but.... it did not work. Any help would be great. Thanks scott


    VB Code:
    1. Dim wc As New Net.WebClient 'the webclient
    2.     Dim bt() As Byte 'the returned bytes
    3.  
    4.     'setup fields to be sent
    5.     Dim fields As New Specialized.NameValueCollection
    6.     fields.Add("j_username", "sls") 'search option
    7.     fields.Add("j_password", "ssfsssfs") 'search box
    8.     fields.Add("LogIn", "") 'button pressed
    9.  
    10.     bt = wc.UploadValues(URL, fields) 'send fields and retrieve response
    11.     html = System.Text.Encoding.ASCII.GetString(bt) 'convert to text
    Last edited by slr; Sep 28th, 2005 at 01:20 PM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Location
    NH
    Posts
    90

    Re: Service in vb.net that needs to login to an asp page

    Still Stuck... Lets say that I have a vb.net app that wants to loginto a page on a web site that requires Name and Password. What am I doing wrong

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Location
    NH
    Posts
    90

    Re: Service in vb.net that needs to login to an asp page

    OK I have given up on the service part for the moment... I switched to an appliction I am making good progress but my question of the day is how do I know when the page has finished downloading after I do this:

    webBrowser.Navigate("http://www.cure.com/")

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Service in vb.net that needs to login to an asp page

    IINM, the webBrowser has an event called DownloadComplete which you can handle.

  5. #5
    Fanatic Member
    Join Date
    May 2005
    Posts
    898

    Re: Service in vb.net that needs to login to an asp page

    Quote Originally Posted by slr
    I am writing a service that needs to login into a .asp page This is what I was attempting but.... it did not work. Any help would be great. Thanks scott


    VB Code:
    1. Dim wc As New Net.WebClient 'the webclient
    2.     Dim bt() As Byte 'the returned bytes
    3.  
    4.     'setup fields to be sent
    5.     Dim fields As New Specialized.NameValueCollection
    6.     fields.Add("j_username", "sls") 'search option
    7.     fields.Add("j_password", "ssfsssfs") 'search box
    8.     fields.Add("LogIn", "") 'button pressed
    9.  
    10.     bt = wc.UploadValues(URL, fields) 'send fields and retrieve response
    11.     html = System.Text.Encoding.ASCII.GetString(bt) 'convert to text

    You say it doesn't work. Does that mean that you're not able to download pages behind the login? Because in the code you posted you are not accepting any cookies. To stay logged in with a webpage you have to offer the same cookiecontainer/collection each time you attempt to download something.
    "so just keep in mind that fantasy is not the same as realtiy and make sure u remember that wii sports may be fun but u cant count on it as exercise ok cool bye" - HungarianHuman

  6. #6
    Fanatic Member
    Join Date
    May 2005
    Posts
    898

    Re: Service in vb.net that needs to login to an asp page

    Here is some C# code that I used to get a cookie from a certain site
    Code:
    				//create the post data
    				string postdata =
    					"redirect=../index.php" +
    					"&username=" + this.txtUserName.Text +
    					"&password=" + this.txtPassWord.Text +
    					"&autologin=on" +
    					"&login=Login";
    
    				byte[] bytes = System.Text.Encoding.UTF8.GetBytes(postdata);
    
    				CookieContainer tmpContainer = new CookieContainer();
    
    				HttpWebRequest req = (HttpWebRequest) WebRequest.Create(loginurlconst);
    				req.CookieContainer = tmpContainer; //necesary??
    
    				req.Method = "POST";
    				req.ContentType = "application/x-www-form-urlencoded";
    				req.ContentLength = postdata.Length;
    
    				//get the stream used to pump out the post data
    				Stream upstream = req.GetRequestStream();
    
    				//send out the POST data
    				upstream.Write(bytes,0,bytes.Length);
    				upstream.Close();
    
    				//get the response
    				HttpWebResponse resp = (HttpWebResponse) req.GetResponse();
    			
    				mcookies = tmpContainer;
    			
    				resp.Close();
    edit: mcookies is a global var that will be used again the next time.
    edit2: and this code doesn't actually get the html, but you can get the response stream from the resp object
    Last edited by grilkip; Oct 2nd, 2005 at 05:21 AM.
    "so just keep in mind that fantasy is not the same as realtiy and make sure u remember that wii sports may be fun but u cant count on it as exercise ok cool bye" - HungarianHuman

  7. #7
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Re: Service in vb.net that needs to login to an asp page

    I was thinking about how in PHP you can say: login.php?user=sls&pass=ssfsssfs, well if it is possible in ASP, then you could use:

    VB Code:
    1. System.Diagnostics.Process.Start("http://www.vbforums.com/login.php?user=" & txtuser & "&pass=" & txtpass & "submit=true")

  8. #8
    Fanatic Member
    Join Date
    May 2005
    Posts
    898

    Re: Service in vb.net that needs to login to an asp page

    Quote Originally Posted by tylerm
    I was thinking about how in PHP you can say: login.php?user=sls&pass=ssfsssfs, well if it is possible in ASP, then you could use:

    VB Code:
    1. System.Diagnostics.Process.Start("http://www.vbforums.com/login.php?user=" & txtuser & "&pass=" & txtpass & "submit=true")
    That only works for GET actions, POST action works differently and is most used for logins.
    "so just keep in mind that fantasy is not the same as realtiy and make sure u remember that wii sports may be fun but u cant count on it as exercise ok cool bye" - HungarianHuman

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width