Using Blogger API (Blogger.aspx)

Jun 15, 2008 at 10:30 PM
I am using the following C# code to make a POST request to Blogger.ASPX. The response I am getting back is "Request from client does not contain valid XML." Unfortunately it doesn't tell me what about my Xml is invalid. It is well-formed. I know that. Here is the Xml I am sending as part of the request:

<?xml version="1.0"encoding="UTF-8"?><methodCall><methodName>blogger.getCategories</methodName><params><param><value><string></string></value></param><param><value><string>MyAwesomeUserName</string></value></param><param><value><string>MySuperPassword</string></value></param></params></methodCall>

Here is the C# code I am using to make the request:

        public static XmlReader CallDasBlogMethod(string blogUrl, string request)
        {
            try
            {
                HttpWebRequest webReq = (HttpWebRequest) WebRequest.Create(blogUrl);
                ASCIIEncoding enc = new ASCIIEncoding();
                byte[] reqData = enc.GetBytes(request);

                webReq.UserAgent =
                    "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3";
                webReq.Method = "POST";
                webReq.ContentType = "application/x-www-form-urlencoded";
                webReq.ContentLength = reqData.Length;
                using (Stream reqStream = webReq.GetRequestStream())
                {
                    reqStream.Write(reqData, 0, reqData.Length);
                }

                using (HttpWebResponse webResp = (HttpWebResponse)webReq.GetResponse())
                {
                    return XmlReader.Create(webResp.GetResponseStream());
                }
            }
            catch (WebException exc)
            {
                return null;
            }
        }

And, finally, here is the Xml I am getting back from the request:


<?xml version="1.0"?>
<methodResponse>
  <fault>
    <value>
      <struct>
        <member>
          <name>faultCode</name>
          <value>
            <i4>0</i4>
          </value>
        </member>
        <member>
          <name>faultString</name>
          <value>
            <string>Request from client does not contain valid XML.</string>
          </value>
        </member>
      </struct>
    </value>
  </fault>
</methodResponse>

Any thoughts on what I might be doing wrong. Or any examples of succesful code would be appreciated in the way a man standing on top of the eiffel tower appreciates jokes about eiffel.net.
Jun 17, 2008 at 3:15 AM
Figured it out. For the record, I was only able to solve it by opening Fiddler2 and then opening up Windows Live Writer and watching the traffic between live writer and my server.

I switched the methodName to metaWeblog.getCategories instead of the blogger version. And made the first string parameter the URL to my blog. After that all is well.

Still, these APIs are rather poorly documented.
Coordinator
Jul 13, 2008 at 7:05 AM
Yes, it's true that the BloggerAPI and XML-RPC sucks deeply.