![]() |
![]()
| ![]() |
![]()
NAMEXML::RPC -- Pure Perl implementation for an XML-RPC client and server. SYNOPSISmake a call to an XML-RPC server: use XML::RPC; my $xmlrpc = XML::RPC->new('http://betty.userland.com/RPC2'); my $result = $xmlrpc->call( 'examples.getStateStruct', { state1 => 12, state2 => 28 } ); create an XML-RPC service: use XML::RPC; use CGI; my $q = new CGI; my $xmlrpc = XML::RPC->new(); my $xml = $q->param('POSTDATA'); print $q->header( -type => 'text/xml', -charset => 'UTF-8' ); print $xmlrpc->receive( $xml, \&handler ); sub handler { my ( $methodname, @params ) = @_; return { you_called => $methodname, with_params => \@params }; } WARNINGVery little maintainance goes into this module. While it continues to work, is has certain quirks that may or may not be fixable without breaking backward compatibility. I strongly recommend that, before deciding what to use in a new project, you look into Randy Ray's RPC::XML module. This seems to be a much more modern approach. DESCRIPTIONXML::RPC module provides simple Pure Perl methods for XML-RPC communication. It's goals are simplicity and flexibility. XML::RPC uses XML::TreePP for parsing. This version of XML::RPC merges the changes from XML::RPC::CustomUA. CONSTRUCTOR AND OPTIONS$xmlrpc = XML::RPC->new();This constructor method returns a new XML::RPC object. Usable for XML-RPC servers. $xmlrpc = XML::RPC->new( 'http://betty.userland.com/RPC2', %options );Its first argument is the full URL for your server. The second argument is for options passing to XML::TreePP, for example: output_encoding => 'ISO-8859-1' (default is UTF-8). You can also define the UserAgent string, for example: my $rpcfoo = XML::RPC->new($apiurl, ('User-Agent' => 'Baz/3000 (Mozilla/1.0; FooBar phone app)')); METHODS$xmlrpc->credentials( 'username', 'password );Set Credentials for HTTP Basic Authentication. This is only secure over HTTPS. Please, please, please do not use this over unencrypted connections! $xmlrpc->call( 'method_name', @arguments );This method calls the provides XML-RPC server's method_name with @arguments. It will return the server method's response. $xmlrpc->receive( $xml, \&handler );This parses an incoming XML-RPC methodCall and call the \&handler subref with parameters: $methodName and @parameters. $xmlrpc->errstr();Returns the last HTTP status code (200 when no remote call has happened yet). Can return 999 for some internal errors $xmlrpc->xml_in();Returns the last XML that went in the client. $xmlrpc->xml_out();Returns the last XML that went out the client. $xmlrpc->indent(indentsize);Sets the xmlout indentation CUSTOM TYPES$xmlrpc->call( 'method_name', { data => sub { { 'base64' => encode_base64($data) } } } );When passing a CODEREF to a value XML::RPC will simply use the returned hashref as a type => value pair. TYPECASTINGSometimes a value type might not be clear from the value alone, typecasting provides a way to "force" a value to a certain type as_stringForces a value to be cast as string. $xmlrpc->call( 'gimmeallyourmoney', { cardnumber => as_string( 12345 ) } ); as_intForces a value to be cast as int as_i4Forces a value to be cast as i4 as_doubleForces a value to be cast as double as_booleanForces a value to be cast as boolean as_base64Forces a value to be cast as base64 as_dateTime_iso8601Forces a value to be cast as ISO8601 Datetime ERROR HANDLINGTo provide an error response you can simply die() in the \&handler function. Also you can set the $XML::RPC::faultCode variable to a (int) value just before dieing. PROXY SUPPORTDefault XML::RPC will try to use LWP::Useragent for requests, you can set the environment variable: CGI_HTTP_PROXY to set a proxy. LIMITATIONSXML::RPC will not create "bool", "dateTime.iso8601" or "base64" types automatically. They will be parsed as "int" or "string". You can use the CODE ref to create these types. AUTHOROriginal author: Niek Albers, http://www.daansystems.com/ Current author: Rene Schickbauer, https://cavac.at COPYRIGHT AND LICENSECopyright (c) 2007-2008 Niek Albers. All rights reserved. This program Copyright (c) 2012-2022 Rene Schickbauer This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|