Possible Duplicate:
how to use cookies with HttpWebRequest
I've been attempting to login to FOPE and query it for results in another thread (Automating Microsoft FOPE (Forefront Online Protection for Exchange) searches).
I finally achieved it using a WPF Webbrowser control. This sadly is a very messy way of doing it, and decidedly very slow as multi-threading or anything of the sort is out of the question. So now I would love to be able to convert it into a HttpWebRequest / HttpWebResponse or WebClient (though I'm unsure about the multi-threading portion of it) setup.
The logical flow is as follows:
- AUTHENTICATE
- Retrieve Page Per Subdomain
- ExtractHREF
- Retrieve
- Detailed Information
- Parse Details
- return CSV
The bold authenticate is the only section I'm struggling with. My WebFu is weak so trying to decipher what I'm seeing in FireBug is laughable at best. It does seem to use a FedAuth cookie but that is as much as I've been able to decipher.
So basically if I want to get step 2 in a web browser I goto this link. It redirects me to here to login.
After authenticating in a web browser it loads the step #2 page and I can continue. Can anyone please help me figure out how to login without using Web Browser (or similar). I've tried the various examples on here using HttpWebRequest but none have succeeded.
Update #1
Someone request I post some sample code so I have. this isn't the only sample I've tried but it looks like it might have a chance.
string email = "username";
string password = "password";
HttpWebRequest request;
HttpWebResponse response;
CookieContainer cookies;
string url = string.Format("https://sts.messaging.microsoft.com/login.aspx?ReturnUrl=%2fDefault.aspx%3fwa%3dwsignin1.0%26wtrealm%3dhttps%253a%252f%252fadmin.messaging.microsoft.com%26wctx%3drm%253d0%2526id%253dpassive%2526ru%253d%25252f%26wct%3d2012-11-30T20%253a22%253a41Z&wa=wsignin1.0&wtrealm=https%3a%2f%2fadmin.messaging.microsoft.com&wctx=rm%3d0%26id%3dpassive%26ru%3d%252f&wct=2012-11-30T20%3a22%3a41Z&email={0}&Password={1}", email, password);
request = (HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = true;
request.CookieContainer = new CookieContainer();
response = (HttpWebResponse)request.GetResponse();
//if (response.StatusCode != HttpStatusCode.Found)
//{
// MessageBox.Show("Something Wrong");
// response.Close();
// request.KeepAlive = false;
// return;
//}
cookies = request.CookieContainer;
response.Close();
request = (HttpWebRequest)WebRequest.Create("https://admin.messaging.microsoft.com/TraceMessage.mvc/Details/123456?rid=1234567890&d=destDomain.com&p=username&a=-5");
request.AllowAutoRedirect = true;
request.CookieContainer = cookies;
response = (HttpWebResponse)request.GetResponse();
using (Stream s = response.GetResponseStream())
{
StreamReader sr = new StreamReader(s);
string line;
while (!sr.EndOfStream)
{
}
}