17 lines
32 KiB
HTML
17 lines
32 KiB
HTML
|
|
<html><head>
|
||
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||
|
|
<title>3. xmlrpc_client</title><link rel="stylesheet" href="html.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.71.1"><link rel="start" href="index.html" title="XML-RPC for PHP"><link rel="up" href="ch07.html" title="Chapter 7. Class documentation"><link rel="prev" href="ch07s02.html" title="2. xmlrpcmsg"><link rel="next" href="ch07s04.html" title="4. xmlrpcresp"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3. xmlrpc_client</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch07s02.html">Prev</a> </td><th width="60%" align="center">Chapter 7. Class documentation</th><td width="20%" align="right"> <a accesskey="n" href="ch07s04.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmlrpc-client"></a>3. xmlrpc_client</h2></div></div></div><p>This is the basic class used to represent a client of an XML-RPC server.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1572"></a>3.1. Creation</h3></div></div></div><p>The constructor accepts one of two possible syntaxes:</p><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$client = new <b class="fsfunc">xmlrpc_client</b>(</code></td><td><var class="pdparam">$server_url</var><code>)</code>;</td><td> </td></tr></table><table border="0" summary="Function argument synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code>string</code> </td><td><code><var class="pdparam">$server_url</var>;</code></td></tr></table><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$client = new <b class="fsfunc">xmlrpc_client</b>(</code></td><td><var class="pdparam">$server_path</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">$server_hostname</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">$server_port</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">$transport</var><code>)</code>;</td><td> </td></tr></table><table border="0" summary="Function argument synopsis" cellspacing="0" cellpadding="0"><tr><td><code>string</code> </td><td><code><var class="pdparam">$server_path</var>;</code></td></tr><tr><td><code>string</code> </td><td><code><var class="pdparam">$server_hostname</var>;</code></td></tr><tr><td><code>int</code> </td><td><code><var class="pdparam">$server_port</var>80;</code></td></tr><tr><td><code>string</code> </td><td><code><var class="pdparam">$transport</var>'http';</code></td></tr></table></div><p>Here are a couple of usage examples of the first form:</p><pre class="programlisting">
|
||
|
|
$client = new xmlrpc_client("http://phpxmlrpc.sourceforge.net/server.php);
|
||
|
|
$another_client = new xmlrpc_client("https://james:bond@secret.service.com:4443/xmlrpcserver?agent=007");
|
||
|
|
|
||
|
|
</pre><p>The second syntax does not allow to express a username and password to be used for basic HTTP authorization as in the second example above, but instead it allows to choose whether xmlrpc calls will be made using the HTTP 1.0 or 1.1 protocol.</p><p>Here's another example client set up to query Userland's XML-RPC server at <span class="emphasis"><em>betty.userland.com</em></span>:</p><pre class="programlisting">
|
||
|
|
$client = new xmlrpc_client("/RPC2", "betty.userland.com", 80);
|
||
|
|
|
||
|
|
</pre><p>The <em class="parameter"><code>server_port</code></em> parameter is optional, and if omitted will default to 80 when using HTTP and 443 when using HTTPS (see the <a href="ch07s03.html#xmlrpc-client-send">xmlrpc_client->send</a> method below).</p><p>The <em class="parameter"><code>transport</code></em> parameter is optional, and if omitted will default to 'http'. Allowed values are either '<span class="symbol">http'</span>, '<span class="symbol">https</span>' or '<span class="symbol">http11'</span>. Its value can be overridden with every call to the <code class="methodname">send</code> method. See the <code class="methodname">send</code> method below for more details about the meaning of the different values.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1657"></a>3.2. Methods</h3></div></div></div><p>This class supports the following methods.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="xmlrpc-client-send"></a>3.2.1. send</h4></div></div></div><p>This method takes the forms:</p><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$response = $client-><b class="fsfunc">send</b>(</code></td><td><var class="pdparam">$xmlrpc_message</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">$timeout</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">$transport</var><code>)</code>;</td><td> </td></tr></table><table border="0" summary="Function argument synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code>xmlrpc_msg</code> </td><td><code><var class="pdparam">$xmlrpc_message</var>;</code></td></tr><tr><td><code>int</code> </td><td><code><var class="pdparam">$timeout</var>;</code></td></tr><tr><td><code>string</code> </td><td><code><var class="pdparam">$transport</var>;</code></td></tr></table><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$responses = $client-><b class="fsfunc">send</b>(</code></td><td><var class="pdparam">$xmlrpc_messages</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">$timeout</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">$transport</var><code>)</code>;</td><td> </td></tr></table><table border="0" summary="Function argument synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code>array</code> </td><td><code><var class="pdparam">$xmlrpc_messages</var>;</code></td></tr><tr><td><code>int</code> </td><td><code><var class="pdparam">$timeout</var>;</code></td></tr><tr><td><code>string</code> </td><td><code><var class="pdparam">$transport</var>;</code></td></tr></table><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$response = $client-><b class="fsfunc">send</b>(</code></td><td><var class="pdparam">$xml_payload</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">$timeout</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">$transport</var><code>)</code>;</td><td> </td></tr></table><table border="0" summary="Function argument synopsis" cellspacing="0" cellpadding="0"><tr><td><code>string</code> </td><td><code><var class="pdparam">$xml_payload</var>;</code></td></tr><tr><td><code>int</code> </td><td><code><var class="pdparam">$timeout</var>;</code></td></tr><tr><td><code>string</code> </td><td><code><var class="pdparam">$transport</var>;</code></td></tr></table></div><p>Where <em class="parameter"><code>xmlrpc_message</code></em> is an instance of <code class="classname">xmlrpcmsg</code> (see <a href="ch07s02.html">xmlrpcmsg</a>), and <em class="parameter"><code>response</code></em> is an instance of <code class="classname">xmlrpcresp</code> (s
|
||
|
|
$client = new xmlrpc_client("phpxmlrpc.sourceforge.net/server");
|
||
|
|
$client->return_type = 'phpvals';
|
||
|
|
$message = new xmlrpcmsg("examples.getStateName", array(new xmlrpcval(23, "int")));
|
||
|
|
$resp = $client->send($message);
|
||
|
|
if ($resp->faultCode()) echo 'KO. Error: '.$resp->faultString(); else echo 'OK: got '.$resp->value();
|
||
|
|
|
||
|
|
</pre><p>For more details about usage of the 'xml' value, see Appendix A.</p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch07s02.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch07.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch07s04.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2. xmlrpcmsg </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 4. xmlrpcresp</td></tr></table></div></body></html>
|