查看文章 |
PHP XMLRPC simple sample
2008年06月20日 星期五 23:43
Download php xmlrpc: http://phpxmlrpc.sourceforge.net/ Online document: http://phpxmlrpc.sourceforge.net/doc-1.1/ Server: <?php require('phpxmlrpc/xmlrpc.inc'); require('phpxmlrpc/xmlrpcs.inc'); function foo () { global $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue; $struct = new xmlrpcval( array( 'code' => new xmlrpcval('200', 'int'), 'msg' => new xmlrpcval('ok', 'string'), ), $xmlrpcStruct); return new xmlrpcresp($struct); } $methodCalls = array( "examples.foo" => array( "function" => "foo", 'signature' => array(array($xmlrpcStruct)) ) ); $xmlrpcServer = new xmlrpc_server($methodCalls, false); $xmlrpcServer->functions_parameters_type = 'phpvals'; // define UTF-8 as the internal encoding for the XML-RPC server $xmlrpcServer->xml_header('UTF-8'); $xmlrpc_internalencoding = 'UTF-8'; // debug level $xmlrpcServer->setDebug(0); // start the service $xmlrpcServer->service(); Client: <?php require('phpxmlrpc/xmlrpc.inc'); $client=new xmlrpc_client('/server.php', 'xmlrpc.sample.com', 80); //$client->setDebug(1); $message = new xmlrpcmsg('examples.foo'); $xmlrpcdoc = $client->send($message); if($xmlrpcdoc->faultcode()==0) { $response=$xmlrpcdoc->value(); $output = var_export($response->scalarval(), true); print '<pre>'; echo $output; print '</pre>'; } else { print 'Error: '.$xmlrpcdoc->faultcode().', '.$xmlrpcdoc->faultstring().'<br>'; } |
最近读者: