tags:

views:

240

answers:

2

Can't seem to figure this out, see code below. Trying to make a GET request to Basecamp and store the XML it returns in memory so I can parse it. Not sure how to exactly 'fire' the request off or get back the XML from it, please advise.

using System;
using System.Web;
using System.Data;
using System.Xml;
using System.Net;
using System.IO;

public class bc2fb : IHttpHandler {

    private struct projectItem
    {
        int projID;
        string projCode;
        string projName;
    }

    private projectItem[] allProjects = new projectItem[100];

    public void ProcessRequest (HttpContext context) {
        context.Response.Write(GetAllProjects().Value);



    }

    public XmlTextReader GetAllProjects()
    {
        HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create("https://company_name.updatelog.com/projects.xml");

        objRequest.Method = "GET";
        objRequest.ContentType = "application/xml";
        objRequest.Accept = "application/xml";

        string creds = "uname:pass";
        byte[] encData_byte = new byte[creds.Length];
        encData_byte = System.Text.Encoding.UTF8.GetBytes(creds);
        string encodedData = Convert.ToBase64String(encData_byte);

        objRequest.Headers.Add("Authorization", "Basic " + encodedData);

        XmlTextReader projectXML = new XmlTextReader(???WHAT TO DO HERE???);

        return projectXML;

    }


    public bool IsReusable {
        get {
            return false;
        }
    }

}
+1  A: 
HttpWebResponse response = (HttpWebResponse)objRequest.GetResponse();
XmlTextReader projectXML = new XmlTextReader(response.GetResponseStream());
Jose Basilio
A: 

You need to use GetResponse, then process it. See A REST Client Library for .NET, Part 1.

Note there is no part 2.

John Saunders