Unexpected error processing XML-RPC request.
EOD exit 0; } # Send an XML document (but don't exit). sub send_xml ($) { my ($xml_string) = @_; my $length = length($xml_string); print <<"EOD"; Status: 200 OK Content-type: text/xml Content-length: $length EOD # We want precise control over whitespace here. print $xml_string; } You can copy the utility routines into your own CGI scripts. ----------------------------------------------------------------------------- 6. Using XML-RPC with Python Fredrik Lundh has provided an excellent XML-RPC library for Python. To install, download the latest version. You can either stick the *.py files in the same directory as your Python code, or you can install them in your system's Python directory. RedHat 6.2 users can type the following: bash$ mkdir xmlrpclib-0.9.8 bash$ cd xmlrpclib-0.9.8 bash$ unzip ../xmlrpc-0.9.8-990621.zip bash$ python python> import xmlrpclib python> import xmlrpcserver python> Control-D bash$ su -c 'cp *.py *.pyc /usr/lib/python1.5/' We import two of the *.py files to trick Python into compiling them. Users of other platforms should consult their Python documentation. For more Python examples, see the article XML-RPC: It Works Both Ways on the O'Reilly Network. ----------------------------------------------------------------------------- 6.1. A Python Client The following program shows how to call an XML-RPC server from Python: import xmlrpclib # Create an object to represent our server. server_url = 'http://xmlrpc-c.sourceforge.net/api/sample.php'; server = xmlrpclib.Server(server_url); # Call the server and get our result. result = server.sample.sumAndDifference(5, 3) print "Sum:", result['sum'] print "Difference:", result['difference'] ----------------------------------------------------------------------------- 7. Using XML-RPC with C and C++ To get a copy of XML-RPC for C/C++, see the [http://xmlrpc-c.sourceforge.net] xmlrpc-c website. You can either download everything in RPM format, or you can build it from source. ----------------------------------------------------------------------------- 7.1. A C Client Save the following code in a file called getSumAndDifference.c: #includeCould not connect to HTTP server.
"; } elseif ($result->faultCode()) { print "XML-RPC Fault #" . $result->faultCode() . ": " . $result->faultString(); } else { $struct = $result->value(); $sumval = $struct->structmem('sum'); $sum = $sumval->scalarval(); $differenceval = $struct->structmem('difference'); $difference = $differenceval->scalarval(); print "
Sum: " . htmlentities($sum) . ", Difference: " . htmlentities($difference) . "
"; } ?> If your webserver doesn't run PHP scripts, see the [http://www.php.net/] PHP website for more information. ----------------------------------------------------------------------------- 9.2. A PHP Server The following script shows how to implement an XML-RPC server using PHP. getParam(0); $x = $xval->scalarval(); $yval = $params->getParam(1); $y = $yval->scalarval(); // Build our response. $struct = array('sum' => new xmlrpcval($x + $y, 'int'), 'difference' => new xmlrpcval($x - $y, 'int')); return new xmlrpcresp(new xmlrpcval($struct, 'struct')); } // Declare our signature and provide some documentation. // (The PHP server supports remote introspection. Nifty!) $sumAndDifference_sig = array(array('struct', 'int', 'int')); $sumAndDifference_doc = 'Add and subtract two numbers'; new xmlrpc_server(array('sample.sumAndDifference' => array('function' => 'sumAndDifference', 'signature' => $sumAndDifference_sig, 'docstring' => $sumAndDifference_doc))); ?> You would normally invoke this as something like http://localhost/path/ sumAndDifference.php. ----------------------------------------------------------------------------- 10. Applications with Built-in XML-RPC Support Several popular Linux applications include support for XML-RPC. These have already been described elsewhere, so we mostly provide pointers to articles. ----------------------------------------------------------------------------- 10.1. Zope Articles on using XML-RPC with Zope are available elsewhere on the web: * XML-RPC Programming with Zope by Jon Udell * Zope XML-RPC at UserLand.Com ----------------------------------------------------------------------------- 10.2. KDE 2.0 KDE 2.0 includes Kurt Ganroth's kxmlrpc daemon, which allows you to script KDE applications using XML-RPC. Here's a short sample application in Python. It shows you how to connect to kxmlrpc, manipulate your KDE address book, and query the KDE trader. If you have any other articles or example code, please see Section 11.2. We'd like to have more information on scripting KDE. ----------------------------------------------------------------------------- 11. About This Document This document is part of the Linux Documentation Project. Thanks go to Dave Winer and maintainers of all the various XML-RPC libraries. ----------------------------------------------------------------------------- 11.1. New Versions of This Document New versions of this document are available at the [http:// xmlrpc-c.sourceforge.net/] XML-RPC for C/C++ website. You can also find reasonably up-to-date versions at the Linux Documentation Project. They also provide this manual in alternate formats, including tarballs and PDF. ----------------------------------------------------------------------------- 11.2. Submitting Other Snippets If you have a sample client or server in another language or environment, we'd love to include it in this manual. To add a new entry, we need the following information: * The URL of the XML-RPC implementation used. * Installation instructions. * A complete, runnable program. * Compilation instructions, if applicable. E-mail your example to the xmlrpc-c-devel mailing list or directly to [mailto:eric.kidd@pobox.com] Eric Kidd. Thank you for your help!