tags:

views:

186

answers:

4

Is it possible to write a C# program that will load up a webpage, pass the webform parameters to login, then click on a link and download the page information? Obviously, I'd be supplying the username and password.

In context, let's say I want to check if there are any new news updates on my school account, which I must login to with my school username/password. Could I supply my program with the desired info and somehow get it to pass these parameters to the webform and continue along the page?

+1  A: 

use the WebRequest class to post the form

examplar: http://msdn.microsoft.com/en-us/library/debx8sh9.aspx

jspcal
+6  A: 

Yes it is possible to programmatically login to a site.

You need to know how your school website handles logins. Say, your school website's login handler is some Login.aspx, and it takes username and password as POST, then you need to send a POST request from your program using WebRequest, adding your username and password as POST variables to your request.

Hope that helps.

Here Be Wolves
Awesome, cool class I had not been introduced to :) Thanks
Chris
+3  A: 

If the login page uses HTTP authentication (your browser displays a username/password prompt), then you can send it through with the URL like so:

http://username:[email protected]/

The WebRequest also allows you to set it's Credentials property and use the username and password that way as well.

Matt
I hope they don't just use HTTP with Chris going to school there. They are going to need HTTPS to keep him from hacking away. ;)
Jason Rowe
+1 for HTTP auth
Here Be Wolves
+1  A: 

An alternative approach to using the WebRequest class is the WebBrowser control. It's basically an Internet Explorer "panel" that you can control both programmatically and through user interaction. The API of the control can be a bit tricky to use, but it does give you access to the DOM of the loaded page, which can then be manipulated through code. This can be handy sometimes. I've used it myself in a couple of web-scraping applications.

Anders Fjeldstad