Journal(2005) | Blog(2006) | RandomLink | WhoAmI | LiveBookmark | HomePage

<<Previous: Goodbye, CET 6  >>Next: Apocalypse RFC 005

XML-PRC Client 客户端编写

Category: Modules   Keywords: XML PRC

暑假里看了些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";
}

<<Previous: Goodbye, CET 6  >>Next: Apocalypse RFC 005

Options: +Del.icio.us

Related items Created on 2005-03-02 00:04:31, Last modified on 2005-05-21 00:13:19
Copyright 2004-2005 All Rights Reserved. Powered by Eplanet && Catalyst 5.62.