06-19-2008, 11:31 PM
i want to crate a program that will display info on a live.xbox.com web site. so i need to be able to log in to microsoft live. i assume i cant do this with a regular username: email@example.com type thing. how would i do this? im just reading source code so i guess i would be using System.Net but i really havnt started anything yet. i just dont know how i would test it without being logged in.
06-20-2008, 05:31 AM
Have you considered using the web browser control? If the user is already logged in via IE, then the web browser control should be logged in when you access those pages.
06-20-2008, 08:54 AM
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.
02-07-2009, 01:26 PM
I am using exactly what u told to.. getting cookies from headers of first request headers["Set-Cookie"] and then setting this cookie for further requests to be made..
but cant get luck for logging in.
My real open post is at