All Entries Tagged With: "rpc"
XML-RPC Variable type detection
XML-RPC is clever enough to automatically detect the data type of the parameters passed to it in the xmlrpc_encode_request function.
Example code:
<?php
$intvar = "77";
settype($intvar, "integer");
$req = xmlrpc_encode_request("NameOfRemoteCall’, $intvar);
echo $req;
?>
Output:
<?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>NameOfRemoteCall</methodName>
<params>
<param>
<value><int>77</int></value>
</param>
</params>
</methodCall>
Create an XML-RPC Request with xmlrpc_encode_request
The process to create an XML-RPC request can be broken up into individual steps:
Serialize the PHP data into XML-RPC format
Create an XML-RPC request by combining HTTP headers and serialized data
Make the call to the service
The PHP function xmlrpc_encode_request can be used to serialize data and it creates the entire XML-RPC request call starting with the [...]
XML-RPC Array Data Type
In XML-RPC, Numerically indexed arrays are passed as a single structure within the value element. Arrays are defined with a specific structure of child elements.
Example Declaration:
<params>
<param>
<value>
<array>
<data>
<value><string>Two</string></value>
<value><boolean>1</boolean></value>
<value><double>42.307400</double></value>
</data>
</array>
</value>
</param>
</params>
The array tag defines the value of the parameter as an array, and the data tag indicates the start of array data. There is a value element for each item [...]
XML-RPC Base64-Encoded Binary Data Type
To transfer binary information via XML-RPC we need to encode the data in base64 (serialization) and use the base64 tags as xml tags.
Example Declaration:
<param>
<value>
<base64>UHSYDhD1423Cc0Ad3NVP4OidTd8E1kRY5Edh</base64>
</value>
</param>
Since PHP does not have a binary data type, developers need to encode files in base64 for XML-RPC transfer by using the file_get_contents function.
XML-RPC Date/Time Data Type
An XML-RPC date/time data type is a primitive data type and specifies a date and a time value, up to the second. It follows the format YYYYMMDDTHH:MM:SS. using Year, month, day, hour, minute, and second conventions. The “T”, however, is a literal to separate Date and time representation. Since there is no date/time data type [...]
XML-RPC Boolean Data Type
Boolean is a primitive data type and can take true or false state. XML-RPC boolean is same as the PHP boolean. In XML-RPC, booleans can only be represented with 1 or 0 unlike PHP where boolean can be represented by the keywords TRUE or FALSE, or a numerical 1 for true and 0 for false. [...]
XML-RPC Double Data Type
XML-RPC Double is a primitive data type and is the double precision signed floating point number. It is similar to float in PHP. From PHP 4 to PHP 5, the double data type has been deprecated in preference of float.
Example Declaration:
<param>
<value><double>-44.352301</double></value>
</param>
XML-RPC Integer Data Type
The integer is a primitive data type and is represented by a four byte signed integer. It is similar to the PHP data type integer. The integer tag can be represented as int or i4, for four byte integer.
Example Declaration:
<param>
<value><int>42</int></value>
</param>
Alternate Example Declaration:
<param>
<value><i4>42</i4></value>
</param>
XML-RPC String Data Type
The string data type is the basic text string and is a primitive data type. It is similar to the string data type in PHP.
Example Declaration:
<param>
<value><string>Hello,Visitor!</string></value>
</param>
The string data type most common data type in XML-RPC and any values of the value element without data type tags inside will default to string.
Example of default string [...]
PHP XML-RPC Data Types
XML-RPC parameters can be one of the following three types.
Scalars: basic primitive data types
Arrays: numerically indexed arrays
Structs: associative arrays
Almost every value must be encapsulated by an element that declares what data type that value is.