02 March 2005
This post may be outdated due to it was written on 2005. The links may be broken. The code may be not working anymore. Leave comments if needed.
暑假里看了些XML的书,fund.perlchina 又出了个 xml-rpc 接口,便想着用 perl 做个客户端试试。
客户端完成后,过几天试着用这几个模块做个服务端/Server.

xml-rpc Server 结构介绍

因为 hoowa 在忙着编写 fund.perl 的 xml-rpc 的第二版, 而当我连接 http://fund.perlchina.org/archive/poda.php 并调用 archive.index 时总返回“404 Not Found”。想着当 hoowa 完成时再写连接 fund.perl 的代码。

http://www.xml-rpc.com 找了个 XML-RPC interface. 地址为:http://xmlrpc.scripting.com/discuss/msgReader$2014

是 Weblogs.Com 的 XML-RPC 接口。大致的结构如下:

url: http://rpc.weblogs.com/RPC2
method: weblogUpdates.ping (weblogname, weblogurl, changesurl=weblogurl, categoryname="none") returns struct
我们的例子为调用 weblogUpdates.ping, 'Scripting News', 'http://www.scripting.com/'
返回值取其中的 message = 'Thanks for the ping.' or 'Thanks for the ping, however we can only accept one ping every half-hour.'

Frontier::RPC


use Frontier::Client;

my $url = 'http://rpc.weblogs.com/RPC2';

my $client = Frontier::Client->new(
    url => $url,
    debug => 1,
);
# Call the remote server and get our result.
my $result = $client->call('weblogUpdates.ping', 'Scripting News', 'http://www.scripting.com/');

print $result->{'message'};
Refrence:
http://www-900.ibm.com/developerWorks/cn/webservices/ws-xpc1/index.shtml (中文)
perldoc Frontier::Client

XML::RPC


my $cli = RPC::XML::Client->new('http://rpc.weblogs.com/RPC2');

my $request = RPC::XML::request->new('weblogUpdates.ping', 'Scripting News', 'http://www.scripting.com/');

my $response = $cli->simple_request($request);

if (!$response) {
    print "$RPC::XML::ERROR \n"; # No response
}
else {
    print $response->{'message'};
}
Refrence:
http://www.perlmonks.org/index.pl?node_id=340799
http://search.cpan.org/dist/RPC-XML/lib/RPC/XML.pm

XMLRPC::Lite


use XMLRPC::Lite;

my $result =  XMLRPC::Lite
      -> proxy('http://rpc.weblogs.com/RPC2')
      -> call('weblogUpdates.ping', 'Scripting News', 'http://www.scripting.com/')
      -> result;

print $result->{'message'};
Refrence:
perldoc XMLPRC::Lite

Further References

Add @ 2005/3/3

问了问 hoowa fund.perlchina 的 xml-rpc 接口,他给了我一段样例。原来是地址错了,挂不得总是回 404 Not Found.
use XMLRPC::Lite;

my $rpc = 'http://fund.perlchina.org/archive/poa.php';

my $client=XMLRPC::Lite->new();
$client->proxy($rpc);
my $archive= $client->call('archive.getindex'=>{order=>'1',limit=>'11'})->result;

foreach (@{$archive}) {
    my %result = %{$_};
    print $result{'title'}, "\n";
}


blog comments powered by Disqus