Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need sample XML-RPC client code for PHP5 [closed]

Tags:

php

xml-rpc

Need a tutorial or some instruction on how to use the XML-RPC library built in to PHP (version PHP Version 5.2.6) for a XML-RPC client. The server is in Python and works.

Google and php.net are failing me.

Update:

Per phpinfo I have xmlrpc-epi v. 0.51 installed. I visited http://xmlrpc-epi.sourceforge.net/ but the xmlrpc-epi-php examples section on the left showed me sf.net's version of a 404.

Update2:

I'm going to use http://phpxmlrpc.sourceforge.net/ and hopefully that will work out for me.

Update3:

The code at http://phpxmlrpc.sourceforge.net/ was straightforward and I got working.

Not closing the question. If anyone wants to chime in with ultra-simple solutions, that would be great!

like image 667
Christopher Mahan Avatar asked Apr 05 '09 05:04

Christopher Mahan


People also ask

What is XML-RPC client?

XML-RPC is a Remote Procedure Call method that uses XML passed via HTTP(S) as a transport. With it, a client can call methods with parameters on a remote server (the server is named by a URI) and get back structured data.

What is difference between RPC and XML-RPC?

XML-RPC has great support in python, in the standard library. SOAP supports document-level transfer, whereas xml-rpc is more about values transfer, although it can transfer structures such as structs, lists, etc. xm-rpc is really about program to program language agnostic transfer. It primarily goes over http/https.

What is XML-RPC request?

XML-RPC requests are a combination of XML content and HTTP headers. The XML content uses the data typing structure to pass parameters and contains additional information identifying which procedure is being called, while the HTTP headers provide a wrapper for passing the request over the Web.

How request is sent in XML-RPC?

Web Technology. Requests are encoded in XML and sent via HTTP POST. Requests are encoded in XML and sent via HTTP GET.


1 Answers

I found this solution in http://code.runnable.com/UnEjkT04_CBwAAB4/how-to-create-a-xmlrpc-server-and-a-xmlrpc-client-for-php

Example for login in webfaction api

// login is the method in the xml-rpc server and username and password
// are the params
$request = xmlrpc_encode_request("login", array('username', 'password'));

$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml\r\nUser-Agent: PHPRPC/1.0\r\n",
'content' => $request
)));

$server = 'https://api.webfaction.com/'; // api url
$file = file_get_contents($server, false, $context);

$response = xmlrpc_decode($file);

print_r($response);

You will see something like:

Array ( [0] => 5d354f42dcc5651fxe6d1a21b74cd [1] => Array ( [username] => yourusername [home] => /home [mail_server] => Mailbox14 [web_server] => Webxxx [id] => 123456 ) )
like image 85
manuelpgs Avatar answered Oct 19 '22 23:10

manuelpgs