Windows live writer’s “Invalid response document” error

In my previous post, I outlined my unsuccessful attempt to use windows live writer (WLW) to connect to the XmlRpc server of PhpWebsite‘s article manager module. I experimented using both the Metaweblog API and the Movable Type API but with no success. When attempting to post an entry, WLW always returned the following error message “The response to the metaWeblog.newPost method received from the weblog server was invalid: Invalid response document returned from XmlRpc server.” However, the entry did get posted. Republishing the same entry would create a new post instead of replacing the one posted earlier. And each time, WLW gave the same error.

I searched the Internet for possible solutions. I found out that the problem is quite common and not unique to PhpWebsite (PWS).  The same problem has also been observed in other blogging platforms such as wordpress. Luckily for wordpress users, there are already solutions posted in several blogs for some of the problems with WLW. Unfortunately for me, the solutions were not applicable for PWS. I could not even find other sites or blogs talking about PWS and WLW except this one. It seems I am the only soul trying to do this in the entire world wide web.

Since most of the websites I’m maintaining are powered by PWS, I thought it is worth the time and effort to figure out the cause of the problem. I am also in need of a good editing application that I can use with PWS. The provided text editor is only good for basic editing and not for more advanced formatting. For instance, using tables in entries can really take a lot of time. Anyway, since I am using WLW in my other blogs, I thought it would be great if I could also use it in my PWS-based websites.

And so I started investigating (debugging). First, I checked the data returned by the XmlRpc server. I inserted a code in the server’s source file to write its output to a file. By comparing the written output with the specification available on the Internet, I confirmed that the error did not originate from the XmlRpc server since the output was according to specification. So I wondered what WLW was complaining about. Well, unless something happened to the returned data before reaching WLW. I started looking for ways to know the actual data received by WLW. Fortunately, I discovered this tool called fiddler, an HTTP debugging tool that logs all HTTP traffic between your computer and the Internet. Fiddler is a freeware and can be used to debug HTTP traffic.

Using fiddler to monitor the traffic between WLW and the HTTP server where the PWS XmlRpc server is running, I posted an entry to PWS. As expected, WLW gave the same error. And this is what I got from fiddler’s log:

Warning:  Cannot modify header information - headers already sent by (output started at D:phpwebsitemodarticleincvalidate_login.php:62) in D:phpwebsitemodarticlelibXML-RPCIXR_Library.inc.php on line 366

Warning:  Cannot modify header information - headers already sent by (output started at D:phpwebsitemodarticleincvalidate_login.php:62) in D:phpwebsitemodarticlelibXML-RPCIXR_Library.inc.php on line 367

Warning:  Cannot modify header information - headers already sent by (output started at D:phpwebsitemodarticleincvalidate_login.php:62) in D:phpwebsitemodarticlelibXML-RPCIXR_Library.inc.php on line 368

Warning:  Cannot modify header information - headers already sent by (output started at D:phpwebsitemodarticleincvalidate_login.php:62) in D:phpwebsitemodarticlelibXML-RPCIXR_Library.inc.php on line 369
<?xml version="1.0"?>
    <methodResponse>
        <params>
             <param>
                 <value>
                     <int>4</int>
                 </value>
             </param>
         </params>
     </methodResponse>

The HTTP server returned a series of PHP warnings together with the xml document expected by WLW! Since WLW did not recognize the warnings and could not just extract the xml part of the returned document, it threw an invalid response document error! So there it is, the source of all my troubles!

Using the above log, it is also possible to know the cause of the problem. As it turned out, the validate_login.php file contained several line breaks after the closing php tag “?>” causing the HTTP server to start sending the returned document when the file was included. A call to the header function by the XmlRpc server generated the warnings, which together with the xml output were sent back by the HTTP server to WLW.

After fixing the validate_login.php file, I still encountered several “invalid response document” errors mostly due to PHP warnings. For instance, some loops using foreach returned warnings when the provided argument was not valid. Fortunately, it was a lot easier locating the source of the problem using fiddler’s log. After fixing the code, I can now successfully post entries to my PWS-based website using WLW. There are still many things that can be improved, but the important thing is the setup is already working.

So the next time you encounter this problem and you are sure that your XmlRpc server is working fine, check those included files for extra line breaks before the PHP opening tag “<?” or after the closing tag “?>”. Those “invalid document response” errors could just be due to those extra line breaks. Also verify whether PHP warnings are suppressed or not. Somewhere in your code some functions maybe returning warnings when the supplied parameters are not properly validated. Or if you cannot pinpoint the problem, try using fiddler to log the traffic between WLW and your XmlRpc server. Then check the data being sent back and forth for clues. Finally, for WLW developers, it would also be nice if WLW has a capability to display the raw data it receives from the XmlRpc server if the user wishes to view it. In this way, it will be a lot easier to debug problems encountered when configuring WLW.

You may also like...

2 Responses

  1. Sylvain says:

    Like you have said, using Fiddler is probably one of the most effective way for debug a communication problem of Windows Live Writer (WLW) with a PHP XML-RPC blog server and sadly, even in 2010, it looks like that there are still a lot of them.

    For those who don’t know how to use Fiddler, I’ve recently posted an article on how to use it as well with a description of some of the most common problems of WLW with XML-RPC; like the presence of a an UTF-8 BOM at the beginning of one of the PHP script files or the presence of extraneous characters at either the beginning (before the opening tag ) of one of the PHP script files:

    http://coding-paparazzi.sylvainlafontaine.com/2010/02/solving-connection-problems-wlw.html

    In the second part (soon to be published), I will cover the problem of the presence of Warning and of Fatal PHP error messages in the XML-RPC response file. Fatal errors are usually the result of some kind of error in the PHP code but you can get a Warning error message simply by having a badly set php.ini file; so it’s often simply a local configuration problem of PHP.

  2. Sakach says:

    I just installed WordPress 2.5.1 and the latest release of Windows Live Writer and found that there is an error in xmlrpc.php. This causes the error as shown in the title of this forum.

    In
    function mw_newPost()
    This line, about halfway in the function is incorrect, and its line number will show up in the log of the latest version of Windows Live Writer, when trying to publish a post. In the log the error is further defined as an “undefined function” call.

    logIO(’O’, ‘Post cats: ‘ . printr($catnames,true));

    printr is not a PHP function nor is it defined in the WordPress code.

    Instead of “printr”, the correct function name is “print_r”

    After making this change the post was published without any other problems:

    logIO(’O’, ‘Post cats: ‘ . print_r($catnames,true));

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.