XML-RPC is a set of standards and a series of implementations that allow remote process calls by programs running in different operating systems and environments based on the Internet.
This Remote Procedure Call uses HTTP as the transmission protocol and XML as the encoding format for transmitting information. The definition of XML-RPC is as simple as possible, but it can also transmit, process, and return complex data structures.
XML-RPC is a Remote Procedure Call protocol that works on the Internet. An XML-RPC message is an HTTP-POST request whose request body is XML. The called method is executed on the server side and the execution result is encoded in XML format and returned.
Procedure Call parameters can be scalar, numeric, String, date, or a complex record or list structure (list ures, that is, array type ).
Example of a 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 <
Request Header requirements:
- In the first row, the URI format can be left unspecified. For example, if the service only handles XML-RPC calls, it can be empty or just a diagonal line. However, if the server is processing various HTTP requests, we should allow the URI to help route the requests to the code that processes the XML-RPC request. (In this example, Uri is/rpc2, which tells the server to route this request to the "rpc2" Response Program .)
- User-Agent and host must be specified.
- Content-Type must be text/XML.
- Content-Length must be specified and correct.
Payload format:
- Valid information is in a single XML structure <methodcall>.
- <Methodcall> must contain a <methodname> subitem, which is a string and contains the name of the method (process) to be called. The string can only contain letters (A-Z in upper and lower cases), numbers (0-9), underscores, dots, colons and diagonal lines (/). The server determines how to interpret the characters of methodname.
- For example, methodname may be the name of a script (the script runs when it receives a request), or it may be a field recorded in a database table, or it may be the path name of a file containing the Directory and file structure.
- If a process call has a parameter, <methodcall> must contain a <Params> subitem. <Params> can contain any number of <param> subitems. Each <param> contains a <value> subitem.
Scalar )
The parameter value <value> can be a scalar. You can use a type label to include the value. If no type is specified, it is considered as string type. Type labels are as follows:
Tag |
Type |
Example |
<I4> or <int> |
4-byte signed integer |
-12 |
<Boolean> |
0 (false) or 1 (true) |
1 |
<String> |
String |
Hello World |
<Double> |
Double-precision signed floating point value |
-12.214 |
<Datetime. iso8601> |
Date/time |
19980717t14: 08: 55 |
<Base64> |
Base64-encoded binary data |
Ew91ignhbid0ihjlywqgdghpcye = |
Structure Data Type (<struct>)
The parameter value can also be of the <struct> type. A <struct> can contain several <member> items, and each <member> contains one <Name> item and one <value> item. The <value> value of <member> can be of any type, scalar type, <array>, or even <struct> (recursive). Example:
<Struct>
<Member>
<Name> lowerbound </Name>
<Value> <I4> 18 </I4> </value>
</Member>
<Member>
<Name> upperbound </Name>
<Value> <I4> 139 </I4> </value>
</Member>
</Struct>
Array data type (<array>)
The parameter value can also be a <array> type <array> with a single <DATA> element. The <DATA> element can contain any number of <value>, here <value> No Name. the Data Types of each <value> can be different, as shown in the following example.
The <value> value of <DATA> can be of any type, scalar type, <struct>, or even <array> (recursive ).
<Array>
<DATA>
<Value> <I4> 12 </I4> </value>
<Value> <string> Egypt </string> </value>
<Value> <Boolean> 0 </Boolean> </value>
<Value> <I4>-31 </I4> </value>
</Data>
</Array>
An example of a XML-RPC response:
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>
XML-RPC response format:
- Unless there is a low-level error, always return 200 OK.
- Content-Type must be text/XML. Content-Length must appear and the value is accurate.
- The response package is a single XML structure <methodresponse>, which can contain a single <Params>, <Params> contains a single <param>, and <param> contains a single <value>.
- <Methodresponse> can also contain a <fault>, which contains a <struct> type <value>, which contains two elements, A <int> value named <faultcode> and a <string> value named <faultstring>.
- <Methodresponse> cannot contain both <fault> and <Params>.
Example of a response to a XML-RPC call failure:
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 parameter parameters. </string> </value>
</Member>
</Struct>
</Value>
</Fault>
</Methodresponse>
Policies and objectives:
- Firewils. The goal of this Protocol is to lay a foundation for compatibility between different environments, and it has no new features beyond CGI capabilities. Firewall software can monitor post requests whose content-type is text/XML.
- Discoverability. We require it to be a simple, clean and scalable format. It should be possible to satisfy: an HTML encoder is able to read a file containing a XML-RPC, understand what it is doing, and be able to modify it and make it work at the first or second request.
- Easy to implement. We also require it to be an easy-to-implement protocol that can quickly run on other environments or operating systems.
References:
- Dave winer, XML-RPC specification, http://www.xmlrpc.com/spec
- Trier, XML-RPC entry, http://www.javaresearch.org/article/showarticle.jsp? Column = 46 & Thread = 4037
- Userland, XML-RPC home,
Http://www.xmlrpc.com/
Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 1929882