XML-PRC (XML Remote Procedure Call),顾名思义,就是通过XML实现远程过程调用(RPC)。
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>
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>
基于TclSOAP的XML-RPC客户端示例
package require XMLRPC package require SOAP # 定义接口 XMLRPC::create UserLogin \ -name "user.login" \ -proxy http://some.host.net/xmlrpc.cgi \ -params {user string passwd string} # 调用 UserLogin "tcler" "i love you"
其中:
如果想观察一下传输的数据内容,可以用如下的示例
proc debug_xmlrpc {method url xml} { puts "$xml" } SOAP::configure user.login -transport debug_xmlrpc