|
-
Sep 27th, 2005, 03:16 PM
#1
Thread Starter
Lively Member
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:
Dim wc As New Net.WebClient 'the webclient
Dim bt() As Byte 'the returned bytes
'setup fields to be sent
Dim fields As New Specialized.NameValueCollection
fields.Add("j_username", "sls") 'search option
fields.Add("j_password", "ssfsssfs") 'search box
fields.Add("LogIn", "") 'button pressed
bt = wc.UploadValues(URL, fields) 'send fields and retrieve response
html = System.Text.Encoding.ASCII.GetString(bt) 'convert to text
Last edited by slr; Sep 28th, 2005 at 01:20 PM.
-
Sep 29th, 2005, 10:06 AM
#2
Thread Starter
Lively Member
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
-
Sep 30th, 2005, 01:53 PM
#3
Thread Starter
Lively Member
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/")
-
Oct 2nd, 2005, 04:13 AM
#4
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.
-
Oct 2nd, 2005, 04:44 AM
#5
Fanatic Member
Re: Service in vb.net that needs to login to an asp page
 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:
Dim wc As New Net.WebClient 'the webclient
Dim bt() As Byte 'the returned bytes
'setup fields to be sent
Dim fields As New Specialized.NameValueCollection
fields.Add("j_username", "sls") 'search option
fields.Add("j_password", "ssfsssfs") 'search box
fields.Add("LogIn", "") 'button pressed
bt = wc.UploadValues(URL, fields) 'send fields and retrieve response
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
-
Oct 2nd, 2005, 04:58 AM
#6
Fanatic Member
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
-
Oct 2nd, 2005, 05:08 AM
#7
Hyperactive Member
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:
System.Diagnostics.Process.Start("http://www.vbforums.com/login.php?user=" & txtuser & "&pass=" & txtpass & "submit=true")
-
Oct 2nd, 2005, 05:22 AM
#8
Fanatic Member
Re: Service in vb.net that needs to login to an asp page
 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:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|