metaWeblog.newPost Example

I wanted to post this for everyone that may be struggling with the metaWeblog API. The MSDN documentation is causing some confusion and I hope it will be corrected soon. In the mean time, here is an example:

Here is an example of a properly formed newPost request:

http://www.xml.com/2003/10/15/examples/metaweblog-example-request.txt

Here is a quick test that I ran using XMLHTTP:

var test ='<?xml version="1.0" encoding="UTF-8"?>';
test = test +
'<methodCall>';
test = test +
'<methodName>metaWeblog.newPost</methodName>';
test = test +
'<params>';
test = test +
'<param>';
test = test +
'<value><string>MyBlog</string></value>';
test = test +
'</param>';
test = test +
'<param>';
test = test +
'<value><string>USERNAME</string></value>';
test = test +
'</param>';
test = test +
'<param>';
test = test +
'<value><string>SECRETWORD</string></value>';
test = test +
'</param>';
test = test +
'<param>';
test = test +
'<value><struct>';
test = test +
'<member>';
test = test +
'<name>category</name>';
test = test +
'<value><string>Books</string></value>';
test = test +
'</member>';
test = test +
'<member>';
test = test +
'<name>description</name>';
test = test +
'<value><string>Hello World</string></value>';
test = test +
'</member>';
test = test +
'<member>';
test = test +
'<name>title</name>';
test = test +
'<value><string>Hello World Title</string></value>';
test = test +
'</member>';
test = test +
'</struct></value>';
test = test +
'</param>';
test = test +
'<param>';
test = test +
'<value><boolean>1</boolean></value>';
test = test +
'</param>';
test = test +
'</params>';
test = test +
'</methodCall>';

req =new ActiveXObject("Microsoft.XMLHTTP");
req.open(
"POST","https://storage.msn.com/storageservice/MetaWeblog.rpc",false);

var
mylength = test.length;

req.setRequestHeader("Content-length", mylength);
req.setRequestHeader(
"User-Agent","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;");
req.setRequestHeader(
"Content-Type","text/xml");

req.send(test);

var
out = req.responseText;
document.write(out);

[5627 byte] By [ShawnClark-MSFT] at [2007-12-27]

Windows Live Developer Forums

Site Classified