PHP Phrasebook
| Querying the Web Service is rather easy. Just instantiate the XML_RPC_Client class (providing name, server, and port of the service), then craft a message with all the parameters, and finally send this message to the server. You receive the result of the Web Service call in returnor an error message. The code calls the Web Services from the previous phrase, assuming that it is accessible using http://localhost/xlmrpc-pear-server.php on port 80. Calling an XML-RPC Web Service (xmlrpc-pear-client.php)
<?php require_once 'XML/RPC.php'; $a = 47; $b = 11; $xmlrpc = new XML_RPC_Client( '/xmlrpc-pear-server.php', 'localhost', 80 ); $msg = new XML_RPC_Message( 'phrasebook.php.add', array( new XML_RPC_Value($a, 'int'), new XML_RPC_Value($b, 'int') ) ); $response = $xmlrpc->send($msg); $result = $response->value(); if (!$response->faultCode()) { echo "$a + $b = " . $result->scalarval(); } else { echo 'Error #' . $response->faultCode() . ': ' . $response->faultString(); } ?>
|
Категории