
06-20-2008, 08:54 AM
|
 |
Fabulous Florist
Forum Leader * Guru *
|
|
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
|
|
|
I wrote an example that logged into the forums once, but for some reason I haven't found it despite searching for it. Still, this isn't a job that necessarily requires the clunky Web Browser control.
The general methodology for logging into a web site requires you to be familiar with the web site and how it operates. An intermediate knowledge of HTML and a basic knowledge of HTTP helps a lot. You need to use tools like the IE Developer toolbar and Wireshark to investigate how the login process on the target website works.
For example, on these forums, the login form sends the username and encrypted password (and something else that I forget) as POST variables to login.php. If the login succeeds, then login.php will set some cookies to store session state (basically so the rest of the forums knows you're logged in.) It's quite simple to emulate this process using code: You create an instance of HttpWebRequest and configure it to POST to login.php, then use the GetRequestStream method to get a stream that lets you write the POST variables. You must also make sure to initialize its Cookies property with a CookieContainer. Once this is done, you use GetResponse to get an HttpWebResponse. If the username and password are correct, the request's Cookies property will be a CookieContainer that you need to use for each additional request to the forums. It sounds complicated, but it only takes about 10 or 15 lines of code.
The problem is, you're going to have to do the work of determining the login process yourself, and MS might change it one day and you'll have to change as well. It's probably better to see if Windows Live exposes some Web Services API that lets you do what you want; most sites these days are starting to do so.
|
|