# phpman > man > XML::RPC(3pm)

## NAME
    [XML::RPC](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ARPC/markdown) -- Pure Perl implementation for an XML-RPC client and server.

## SYNOPSIS
    make a call to an XML-RPC server:

        use [XML::RPC](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ARPC/markdown);

        my $xmlrpc = [XML::RPC](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ARPC/markdown)->new('<http://betty.userland.com/RPC2>');
        my $result = $xmlrpc->call( 'examples.getStateStruct', { state1 => 12, state2 => 28 } );

    create an XML-RPC service:

        use [XML::RPC](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ARPC/markdown);
        use CGI;

        my $q      = new CGI;
        my $xmlrpc = [XML::RPC](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ARPC/markdown)->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 };
        }

## DESCRIPTION
    [XML::RPC](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ARPC/markdown) module provides simple Pure Perl methods for XML-RPC communication. It's goals are
    simplicity and flexibility. [XML::RPC](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ARPC/markdown) uses [XML::TreePP](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ATreePP/markdown) for parsing.

## CONSTRUCTOR AND OPTIONS
  $xmlrpc = [XML::RPC](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ARPC/markdown)->new();
    This constructor method returns a new [XML::RPC](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ARPC/markdown) object. Usable for XML-RPC servers.

  $xmlrpc = [XML::RPC](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ARPC/markdown)->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](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ATreePP/markdown), for example: output_encoding => 'ISO-8859-1' (default is UTF-8).

## METHODS
  $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->xml_in();
    Returns the last XML that went in the client.

  $xmlrpc->xml_out();
    Returns the last XML that went out the client.

## CUSTOM TYPES
  $xmlrpc->call( 'method_name', { data => sub { { 'base64' => encode_base64($data) } } } );
    When passing a CODEREF to a value [XML::RPC](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ARPC/markdown) will simply use the returned hashref as a type =>
    value pair.

## ERROR HANDLING
    To provide an error response you can simply die() in the \&handler function. Also you can set
    the $[XML::RPC::faultCode](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ARPC%3A%3AfaultCode/markdown) variable to a (int) value just before dieing.

## PROXY SUPPORT
    Default [XML::RPC](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ARPC/markdown) will try to use [LWP::Useragent](https://www.chedong.com/phpMan.php/perldoc/LWP%3A%3AUseragent/markdown) for requests, you can set the environment
    variable: CGI_HTTP_PROXY to set a proxy.

## LIMITATIONS
    [XML::RPC](https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ARPC/markdown) 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.

## AUTHOR
    Niek Albers, <http://www.daansystems.com/>

## COPYRIGHT AND LICENSE
    Copyright (c) 2007-2008 Niek Albers. All rights reserved. This program is free software; you can
    redistribute it and/or modify it under the same terms as Perl itself.

