|
xmlrpc_encode_request
Generates XML for a method request
(PHP 4 >= 4.0.7, PHP 5)
Warning:
This function is EXPERIMENTAL. The behaviour of this function, the name of this function, and anything else documented about this function may change without notice in a future release of PHP. Use this function at your own risk. Parameters
ExamplesExample 2647. XMLRPC client functions example<?php Related Examples ( Source code ) » xmlrpc_encode_request Examples ( Source code ) » XmlRpcServer extends HttpResponse Examples ( Source code ) » XmlRpcClient using HttpRequest Code Examples / Notes » xmlrpc_encode_requesthfuecks
This function should be used by an XML-RPC client to create an XML payload for an XML-RPC request; <?php $params = "system.methodSignature"; $method = "system.methodHelp"; $request = xmlrpc_encode_request($method,$params); echo ( $request ); ?> Produces; <?xml version='1.0' encoding="iso-8859-1" ?> <methodCall> <methodName>system.methodHelp</methodName> <params> <param> <value> <string>system.methodSignature</string> </value> </param> </params> </methodCall> The second argument recognises the type of variable and generates the correct XML-RPC structure. See xmlrpc_encode() for more details. giunta dot gaetano
Take care that this function will generate invalid xmlrpc content when invoked with certain parameters (said content will be happily parsed by the lib itself, but not by other implementations). xmlrpc_encode_request(null, null) will generate a response without a value xmlrpc_encode_request('myfunc', array('faultCode' => 666, 'faultString' => 'hello world') will generated a request containing a <fault> member instead of <params> handco
Simple OO client with function Overload : the php metho test_helloworld is translated to xmlrpc method test.helloworld. class RpcClient { private $_methods; private $_context; private $_url; function __construct ($url, $user, $passwd) { $auth = base64_encode(sprintf('%s:%s', $user,$passwd)); $this->_context = stream_context_create(array( 'http' => array( 'method' => 'POST', 'header' => "Content-Type: text/xml\r\n". "Authorization: Basic $auth" , ) )); $this->_url = $url; $this->registerMethod ("Test_HelloWorld"); } function __call($methodName, $params) { if (array_key_exists($methodName,$this->_methods)) { // on appelle la fonction RPC $m = str_replace('_', '.', $methodName); $r = xmlrpc_encode_request($m, $params,array('verbosity'=>'newlines_only')); $c = $this->_context; stream_context_set_option($c,'http','content',$r); $f = file_get_contents($this->_url,false,$c); $resp = xmlrpc_decode($f); return $resp; } else { // on appelle la fonction de l'objet call_user_method_array($methodName, $this,$params); } } private function registerMethod ($method) { $this->_methods[$method] = true; } }
Note that as far as I can tell, the characters generated by PHP in the base64 fields don't appear to violate the XML-RPC standard at all. XML-RPC messages *are* in XML format, and as such, the XML entities should be getting decoded before being passed to a base64 decoder. So, the previously-mentioned Jakarta-based XML-RPC server appears to violate the XML spec. i.e. There's nothing here that needs to be "fixed" in PHP.
php
For examples / documentation of the array output_options, see http://xmlrpc-epi.sourceforge.net/main.php?t=php_api#output_options In short, output_options lets you send compact xmlrpc (without all the "pretty whitespace" xmlrpc_encode adds normally), apply an own escaping table prior to sending, set the encoding, and a couple of other things (the page even says something about soap 1.1 ... I don't know details). kelly
Binary strings (set with xmlrpc_set_type) go into a <base64>...</base64> block like you'd expect. But after every 80th character, this function inserts the XML entity " ", which is a Unicode newline, as if to cause a line-wrap, which is admittedly silly. Silly though it may be, it causes real problems for some XML-RPC servers, such as http://jakarta.apache.org/xmlrpc/ (nee Helma). Stripping out those entities with something like $req = preg_replace('/ /', '', xmlrpc_encode_request("my.method", $args)); works around the problem. brian
As per documentation on xmlrpc-epi's site, this function also can create both a methodCall and a methodResponse. to create a methodCall: xmlrpc_encode_request(null,$params); to create a methodRequest: xmlrpc_encode_request("methodName",$params); --- The documentation on this is abysmal. I know this is opensource, but it has been around for quite a while now. |
Change Languagexmlrpc_decode_request xmlrpc_decode xmlrpc_encode_request xmlrpc_encode xmlrpc_get_type xmlrpc_is_fault xmlrpc_parse_method_descriptions xmlrpc_server_add_introspection_data xmlrpc_server_call_method xmlrpc_server_create xmlrpc_server_destroy xmlrpc_server_register_introspection_callback xmlrpc_server_register_method xmlrpc_set_type |