June 25, 2009

XML-RPC Clients In Python and Perl

I was just writing some XML-RPC code and wanted to post some simple examples of how to talk to an XML-RPC server with some simple client-side code. Here are examples in both Python and Perl.

The examples below show how to connect to an XML-RPC server and call the service's start() method.

a simple XML-RPC client in Python:

#!/usr/bin/env python

import xmlrpclib

host = 'http://localhost'
port = '8888'

server = xmlrpclib.Server('%s:%s' % (host, port))
response = server.start()
print response

a simple XML-RPC client in Perl (using the Frontier-RPC module):

#!/usr/bin/perl -w

use strict;
use Frontier::Client;

my $host = 'http://localhost';
my $port = '8888';

my $server = Frontier::Client->new('url' => "$host:$port");
my $response = $server->call('start');
print $response;
Post a Comment