Forum > Networking and Web Programming
[Solved:Change to Synapse][Ask] Indy 10 XMLRPC client
Mujie:
Hi,
I'm trying to make a XML-RPC server with a simple XML-RPC client using IXR (The Incutio XML-RPC Library for PHP). A simple XML server is successfully to run, as well as a XML client.
Server with IXR :
--- Code: PHP [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---<?php//xmlrpc-server.phpinclude('IXR_Library.php'); function addTwoNumbers($args) {$number1 = $args[0];$number2 = $args[1];return $number1 + $number2;} $server = new IXR_Server(array('demo.addTwoNumbers' => 'addTwoNumbers'));?>
Client with IXR :
--- Code: PHP [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---<?php//xmlrpc-client-ixr.phpinclude('IXR_Library.php');$client = new IXR_Client('hxxp://localhost/xmlrpc/xmlrpc-server.php');if (!$client->query('demo.addTwoNumbers', '100', '26')) { die('Something went wrong - '.$client->getErrorCode().' : '.$client->getErrorMessage());} echo '<pre>';print_r($client->getResponse());echo '</pre>';?>
Client without IXR :
--- Code: PHP [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---<?php//xmlrpc-client-nonixr.php$request = xmlrpc_encode_request('demo.addTwoNumbers', array('100', '26'));$context = stream_context_create(array('http' => array('method' => "POST",'header' => "Content-Type: text/xml\r\nUser-Agent: PHPRPC/1.0\r\n",'content' => $request))); $server = 'hxxp://localhost/xmlrpc/xmlrpc-server.php';$file = file_get_contents($server, false, $context);$response = xmlrpc_decode($file);echo '<pre>'.$response.'</pre>';?>
The result from client side is "126";
My question is, how use Indy 10 to build desktop client side as code describe above, parse it and show the result? I try with code below, but no luck :(
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---use .... IdHTTP, ........procedure TForm1.Button1Click(Sender: TObject);var lHTTP: TIdHTTP; lParamList: TStringList; Result: String; begin lHTTP := TIdHTTP.Create(nil); lHTTP.Request.ContentType := 'text/xml'; lHTTP.Request.Accept := '*/*'; lHTTP.Request.Connection := 'Keep-Alive'; lHTTP.Request.Method := 'POST'; lParamList := TStringList.Create; lParamList.Add('demo.addTwoNumbers'); lParamList.Add('100'); lParamList.Add('26'); try Result := lHTTP.Post('hxxp://localhost/xmlrpc/xmlrpc-server.php', lParamList); finally FreeAndNil(lHTTP); FreeAndNil(lParamList); end; Memo1.Text := Result; end;
Laksen:
Take a look at the specification, it's very simple: http://www.xmlrpc.com/spec
So essentially what you should send, should be something like
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- lParamList.Add('<?xml version="1.0"?>'); lParamList.Add('<methodCall>'); lParamList.Add(' <methodName>demo.addTwoNumbers</methodName>'); lParamList.Add(' <params>'); lParamList.Add(' <param>'); lParamList.Add(' <value><i4>100</i4></value>'); lParamList.Add(' <value><i4>26</i4></value>'); lParamList.Add(' </param>'); lParamList.Add(' </params>'); lParamList.Add('</methodCall>');
And the response(without headers) should look something like:
--- Code: ---<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value><i4>126</i4></value>
</param>
</params>
</methodResponse>
--- End code ---
You can use TXMLDocument to parse that
Mujie:
--- Quote from: Laksen on October 18, 2010, 05:18:52 pm ---Take a look at the specification, it's very simple: http://www.xmlrpc.com/spec
So essentially what you should send, should be something like
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- lParamList.Add('<?xml version="1.0"?>'); lParamList.Add('<methodCall>'); lParamList.Add(' <methodName>demo.addTwoNumbers</methodName>'); lParamList.Add(' <params>'); lParamList.Add(' <param>'); lParamList.Add(' <value><i4>100</i4></value>'); lParamList.Add(' <value><i4>26</i4></value>'); lParamList.Add(' </param>'); lParamList.Add(' </params>'); lParamList.Add('</methodCall>');
--- End quote ---
Still no luck, I always got this :
--- Code: ---<?xml version="1.0"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>-32700</int></value>
</member>
<member>
<name>
</name>
<value><string>parse error. not well formed</string></value>
</member>
</struct>
</value>
</fault>
</methodResponse>
--- End code ---
Even I change <value><i4>100</i4></value> with <value><int>100</int></value>.
Anymore clue ?
Laksen:
My mistake
--- Code: --- lParamList.Add('<?xml version="1.0"?>');
lParamList.Add('<methodCall>');
lParamList.Add(' <methodName>demo.addTwoNumbers</methodName>');
lParamList.Add(' <params>');
lParamList.Add(' <param>');
lParamList.Add(' <value><i4>100</i4></value>');
lParamList.Add(' </param>');
lParamList.Add(' <param>');
lParamList.Add(' <value><i4>26</i4></value>');
lParamList.Add(' </param>');
lParamList.Add(' </params>');
lParamList.Add('</methodCall>');
--- End code ---
Mujie:
@Laksen : no, still not working, same error messages. Please take a look at http://stackoverflow.com/questions/301991, I follow their comment. Maybe Indy can't do this? Just guessing.
Navigation
[0] Message Index
[#] Next page