0

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:

  1. AUTHENTICATE
  2. Retrieve Page Per Subdomain
  3. ExtractHREF
  4. Retrieve
  5. Detailed Information
  6. Parse Details
  7. 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)
            {

            }
        }
Community
  • 1
  • 1
lordzero
  • 59
  • 1
  • 9
  • Problem is that alone hasn't worked. :/ – lordzero Nov 29 '12 at 22:39
  • Added code, though currently I've tried quite a few different solutions. I just ran this one and had 0 cookies in CookieContainer cookies; – lordzero Nov 30 '12 at 20:38
  • The login page has a form. Where are you HTTP POSTing the user name and password in your code? – mbeckish Nov 30 '12 at 21:03
  • At the string url line, at least I thought so. Look at the end of the string. If this isn't so, what's a better solution? – lordzero Dec 01 '12 at 02:37
  • And is that how the web site submits the form? By doing a HTTP GET to that URL with that exact query string? Have you tried copying and pasting that URL with that query string into a browser to see if it works? – mbeckish Dec 03 '12 at 15:20

0 Answers0