tags:

views:

279

answers:

1

I need to connect a piece of middleware I'm writing in C# to Adobe Connect. Their API returns all data queryied as an XML document. The issue I'm having is this: I need to check a response to see if the login attempt is successful, and if it is I need to retrieve the cookie from the HTTP headers so that I can use that cookie to perform the various actions the application requires. How would I go about this?

This is what a successful login attempt looks like on the XML side of things:

<results>
     <status code="ok"/>
</results>

Any help would be appreciated.

+3  A: 

Use an HttpWebRequest and an HttpWebResponse (or just WebRequest/WebResponse if they give you enough functionality). When you've got the response, you can query the headers and then get the content as a stream. You can parse the stream in XML using any of the normal XML APIs.

Here's an example fetching a page and displaying both a header and the first part of the content:

using System;
using System.IO;
using System.Net;

class Test
{
    static void Main()
    {
        WebRequest request = WebRequest.Create("http://csharpindepth.com");
        using (WebResponse response = request.GetResponse())
        {
            Console.WriteLine(response.Headers["Content-Type"]);
            using (StreamReader reader = new StreamReader
                       (response.GetResponseStream()))
            {
                string content = reader.ReadToEnd();
                Console.WriteLine(content.Substring(0, 120));
            }
        }
    }
}
Jon Skeet
That worked awesomely. Thanks for the help, sir!
Xir