Reply to comment

Making remote XML-RPC calls with QXmlRpc_Client

XMLRPC Overview

Getting information accross XML-RPC

Hello folks, this is my weekly contribution to QCubed project a new XML-RPC client plugin.

QXmlRpc_Client provides a client for XML-RPC based web services, as defined in this specification. If the server you need to talk to responds to XML-RPC, you'll save yourself a bunch of time if you use this plugin.

To look into how the plugin works in detail, let's consider a sample web service defined at http://phpxmlrpc.sourceforge.net/server.php?methodName=examples.getStateName. This example is really simple: given a number from 1 to 51, the service returns the name of the USA state that has that "id". If you enter a number outside of that range, the service returns an error. Go ahead and experiment with it at http://examples.qcu.be/assets/plugins/QXmlRpcClient/example/qxmlrpc_client.php.

Let's now look at how to use the client. It's really straightforward - first, initialize a QXmlRpc_Client object. Then, create an array of parameters that you want to pass to the web service. Each parameter has to be wrapped with a QXmlRpc_Client::prepare() call to format the parameters appropriately.

$aParams = array( QXmlRpc_Client::prepare((int) $this->txtState->Text) );

Then, make the actual request - note that requests are synchronous (i.e. execution will go to the next line of code after you get the actual response). That said, if you are making the call in a QAjaxAction, the QForm will still be responsive to the user.

list($success, $response) = $client->request(
'phpxmlrpc.sourceforge.net', // server name
'/server.php', // server endpoint
'examples.getStateName',// method name
$aParams // parameters that we prepared above
);

Result of making a request is a key-value pair. The first variable is a boolean that indicates success or failure; the second one is an array with the details.

Enjoy it.

 

Reply

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <b> <address> <blockquote> <br> <caption> <center> <code> <dd> <del> <div> <dl> <dt> <em> <font> <h2> <h3> <h4> <h5> <h6> <hr> <i> <img> <li> <ol> <p> <pre> <span> <strong> <sub> <sup> <table> <tbody> <td> <tfoot> <th> <thead> <tr> <u> <ul> <tr>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
5 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.