Introduction to XML-RPC Web service protocol [i]

Source: Internet
Author: User

XML-RPC is a cross-platform, remote invocation protocol that is suitable for transmission over the Internet. The client sends a POST request to the server via the HTTP protocol, the post data is encoded with XML, the server receives the request, extracts the post data, gets the calling method and parameters, then executes, and finally returns the result of the XML format.

With XML-RPC protocol, different servers can communicate with each other and call remote procedures. Simpler than SOAP,XML-RPC, and more suitable for web development.

A simple 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>

It's easy to understand even if it's never touched: Examples.getstatename is a remote calling method, 41 is a call parameter, and the server location is BETTY.USERLAND.COM/RPC2

Send Header requirements:

1, the path after post is not required, if the server only processes XML-RPC requests, this can be omitted; If the server also processes HTTP requests, the server's path should be fully filled.

2, User-agent and host must be specified.

3, Content-type must be text/xml format.

4, the number of bytes sent must be specified, and must be correct.

5, other header information can be added as needed.

PHP is easy to implement $xml = "Some request in XML format"; Request data
$fp = fopen ($host, $port, $error, $ERRSTR, 10);
if ($error)
Die ($ERRSTR);
Fwrite ($fp, "post/http1.1");
Fwrite ($fp, "User-agent:xml-rpc Client");
Fwrite ($FP, "Host: $host");
Fwrite ($fp, "content-type:text/xml");
Fwrite ($FP, "Content-length:". Strlen ($xml). " " );
while ($data = Fread ($fp, 1024)) {
Do something here
}
Fclose ($FP);

The XML request has only one root element <methodcall>, immediately after the root element is the calling method name <methodname>, indicating the remote procedure to invoke, and finally the argument list. The parameter list starts with <params>, with each parameter under <param> included. Parameter must indicate a numeric type, if not indicated, the default is string type. The simple types that can be supported are int (or I4), Boolean, String, base64, double, datetime.iso8601, complex data types support array arrays and struct struct types, if you want to transfer data for an object type, you must first convert the object to a struct type, and then export the object's properties to struct.

struct type: < struct >
    < member >
       < name > lowerbound </name >
       < value >< i4 > </i4 ></ Value >
     </member >
    < member >
        < name > upperbound </name >
       < value >< I4 > 139 </i4 ></value >
     </member >
  </struct >

  Array Type:   < array >
    < data >
       < value >< I4 > </i4 ></value >
       < value >< String > Egypt </string ></value >
       < value >< Boolean & Gt 0 </Boolean ></value >
       < value >< I4 > -31 </I4 ; </value >
      </data >
  </array >   Complex data types can be nested on each other: < struct >
    < member >
       < name > Lowerbound &L t;/name >
       < value >< i4 > </i4 ></value >
&N bsp;      </>
    < member >
     &n

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.