Overview
XML-RPC is a remote procedure calling protocol that works over the Internet.
An XML-RPC message is an HTTP-POST request. The body of the request is in XML. A procedure executes on the server and the value it returns is also formatted in XML.
Procedure parameters can be scalars, numbers, strings, dates, etc.; and can also be complex record and list structures.
Request example
Here's an example of an XML-RPC request:
POST /RPC2 HTTP/1.0
User-Agent: Frontier/5.1.2 (WinNT)
Host: betty.userland.com
Content-Type: text/xml
Content-length: 181
<?xml version="1.0"?>
<methodCall>
<methodName>examples.getStateName</methodName>
<params>
<param>
<value><i4>41</i4></value>
</param>
</params>
</methodCall>
Header requirements
The format of the URI in the first line of the header is not specified. for example, it cocould be empty, a single slash, if the server is only handling XML-RPC CILS. however, if the server is handling a mix of incoming HTTP requests, we allow the URI to help route the request to the code that handles XML-RPC requests. (In the example, the URI is/rpc2, telling the server to route the request to the "rpc2" responder .)
A User-Agent and host must be specified.
The Content-Type is text/XML.
The Content-Length must be specified and must be correct.
Payload format
The payload is in XML, a single <methodcall> structure.
The <methodcall> must contain a <methodname> sub-item, a string, containing the name of the method to be called. the string may only contain identifier characters, upper and lower-case A-Z, the numeric characters, 0-9, underscore, Dot, colon and slash. it's entirely up to the server to decide how to interpret the characters in a methodname.
For example, the methodname cocould be the name of a file containing a script that executes on an incoming request. it cocould be the name of a cell in a database table. or it cocould be a path to a file contained within a hierarchy of folders and files.
If the procedure call has parameters, the <methodcall> must contain a <Params> sub-item. the <Params> sub-item can contain any number of <param> S, each of which has a <value>.
Scalar <value> S
<Value> S can be scalars, type is indicated by nesting the value inside one of the tags listed in this table:
Tag |
Type |
Example |
<I4> or <int> |
Four-byte signed integer |
-12 |
<Boolean> |
0 (false) or 1 (true) |
1 |
<String> |
String |
Hello World |
<Double> |
Double-precision signed floating point number |
-12.214 |
<Datetime. iso8601> |
Date/time |
19980717t14: 08: 55 |
<Base64> |
Base64-encoded binary |
Ew91ignhbid0ihjlywqgdghpcye = |
If no type is indicated, the type is string.
<Struct> S
A value can also be of Type <struct>.
A <struct> contains <member> S and each <member> contains a <Name> and a <value>.
Here's an example of a two-element <struct>:
<struct>
<member>
<name>lowerBound</name>
<value><i4>18</i4></value>
</member>
<member>
<name>upperBound</name>
<value><i4>139</i4></value>
</member>
</struct>
<Struct> S can be recursive, any <value> may contain a <struct> or any other type, including an <array>, described below.
<Array> S
A value can also be of Type <array>.
An <array> contains a single <DATA> element, which can contain any number of <value> S.
Here's an example of a four-element array:
<array>
<data>
<value><i4>12</i4></value>
<value><string>Egypt</string></value>
<value><boolean>0</boolean></value>
<value><i4>-31</i4></value>
</data>
</array>
<Array> elements do not have names.
You can mix types as the example abve into strates.
<Arrays> S can be recursive, any value may contain an <array> or any other type, including a <struct>, described above.
Response example
Here's an example of a response to an XML-RPC request:
HTTP/1.1 200 OK
Connection: close
Content-Length: 158
Content-Type: text/xml
Date: Fri, 17 Jul 1998 19:55:08 GMT
Server: UserLand Frontier/5.1.2-WinNT
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value><string>South Dakota</string></value>
</param>
</params>
</methodResponse>
Response format
Unless there's a lower-level error, always return 200 OK.
The Content-Type is text/XML. Content-Length must be present and correct.
The body of the response is a single XML structure, a <methodresponse>, which can contain a single <Params> which contains a single <param> which contains a single <value>.
The <methodresponse> cocould also contain a <fault> which contains a <value> which is a <struct> containing two elements, one named <faultcode>, an <int> and one named <faultstring>, A <string>.
A <methodresponse> can not contain both a <fault> and a <Params>.
Fault Example
HTTP/1.1 200 OK
Connection: close
Content-Length: 426
Content-Type: text/xml
Date: Fri, 17 Jul 1998 19:55:02 GMT
Server: UserLand Frontier/5.1.2-WinNT
<?xml version="1.0"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>4</int></value>
</member>
<member>
<name>faultString</name>
<value><string>Too many parameters.</string></value>
</member>
</struct>
</value>
</fault>
</methodResponse>
Strategies/goals
Firewils.The goal of this Protocol is to lay a compatible Foundation infrastructure SS different environments, no new power is provided beyond the capabilities of the CGI interface. firewall software can watch for posts whose content-type is text/XML.
Discoverability.We wanted a clean, extensible format that's very simple. it shoshould be possible for an HTML coder to be able to look at a file containing an XML-RPC procedure call, understand what it's doing, and be able to modify it and have it work on the first or second try.
Easy to implement.We also wanted it to be an easy to implement Protocol that cocould quickly be adapted to run in other environments or on other operating systems.