XML-RPC is a protocol transmitted via HTTP, the standard for data exchange between web servers and web browsers. The information that it transmits is not web content. Instead, it is XML data encoded in a specific way.
Two kinds of data exchanges are conducted using XML-RPC: client requests and server responses.
An XML-RPC request is XML data sent to a web server as part of an HTTP post request. A post request normally is used to transmit data from a web browser to a web server— Java servlets, common gateway interface programs, and other software collect the data from a post request and send Hypertext Markup Language (HTML) back in response.
When you submit an email from a web page or vote in an online poll, you’re either using post or a similar HTTP request called get. XML-RPC, on the other hand, is simply using HTTP as a convenient protocol for communicating with a server and receiving a response back. The request consists of two parts: the HTTP headers required by the post transmission and the XML-RPC request, which is expressed as XML. Listing 20.1 contains an example of an XML-RPC request.
In Listing 20.1, lines 1–6 are the HTTP headers, and lines 8–18 are the XML-RPC
request. This listing tells you the following:
· The XML-RPC server is at http://www.advogato.org/XMLRPC (lines 1–2).
· The remote method being called is test.square (line 10).
· The method is being called with one argument, an integer with a value of 13 (lines 2–16).
Unlike their counterparts in Java, method names in an XML-RPC request do not include parentheses. They consist of the name of an object followed by a period and the name of the method or simply the name of the method, depending on the XML-RPC server..
An XML-RPC response is XML data that is sent back from a web server like any other HTTP response. Again, XML-RPC piggybacks on top of an established process—a web server sending data via HTTP to a web browser—and uses it in a new way. The response also consists of HTTP headers and an XML-RPC response in XML format. Listing 20.2 contains an example of an XML-RPC response.
In Listing 20.2, lines 1–8 are the HTTP headers, and lines 10–19 are the XML-RPC response. You can learn the following things from this listing:
· The response is 157 bytes in size and in XML format (lines 6 and 8).
· The value returned by the remote method is an integer that equals 169 (line 15).
An XML-RPC response contains only one argument, contrary to what you might expect from the params tag in line 12. If the remote method does not return a value—for example, it might be a Java method that returns void—an XML-RPC server still returns something. This return value can be primitive data, strings, arrays of varying dimensions, and more sophisticated data structures such as key-value pairs (the kind of thing you would implement in Java using HashMap or one of its subclasses).