Hi all,

i surely need some help regarding the use of cgi with json rpc. I looked at the demo1 example and tested it with testcgi app from the command line. All was fine. Then i tried to run the demo1 cgi app from apache with a php json rpc client. It seems that i can't find the right uri to put into the php call. All calls goes to the default action named 'manual'.

I renamed the handler name from echo to myecho to resolve a conflict with the php's function echo. The following code for calling the cgi working fine :

<?php

include('JsonRpcClient.php');

$api = new JsonRpcClient('http://localhost/cgi-bin/demo.exe');
print $api->myecho("Hello from JSON RPC");

?>

Now, how do i call the dispatcher handler ? I tried to change the uri like this

$api = new JsonRpcClient('http://localhost/cgi-bin/demo.exe/dispatch');
$api = new JsonRpcClient('http://localhost/cgi-bin/demo.exe?action=dispatch');

Nothing worked ...

Can someone give me a hint ?

PS: I attached the JsonRpcClient.php ...

regards,
--
Dimitrios Chr. Ioannidis

uri = $uri; } private function generateId() { $chars = array_merge(range('A', 'Z'), range('a', 'z'), range(0, 9)); $id = ''; for($c = 0; $c < 16; ++$c) $id .= $chars[mt_rand(0, count($chars) - 1)]; return $id; } public function __call($name, $arguments) { $id = $this->generateId(); $request = array( 'jsonrpc' => '2.0', 'method' => $name, 'params' => $arguments, 'id' => $id ); $jsonRequest = json_encode($request); $ctx = stream_context_create(array( 'http' => array( 'method' => 'POST', 'header' => 'Content-Type: application/json\r\n', 'content' => $jsonRequest ) )); $jsonResponse = file_get_contents($this->uri, false, $ctx); if ($jsonResponse === false) throw new JsonRpcFault('file_get_contents failed', -32603); $response = json_decode($jsonResponse); if ($response === null) throw new JsonRpcFault('JSON cannot be decoded', -32603); if ($response->id != $id) throw new JsonRpcFault('Mismatched JSON-RPC IDs', -32603); if (property_exists($response, 'error')) throw new JsonRpcFault($response->error->message, $response->error->code); else if (property_exists($response, 'result')) return $response->result; else throw new JsonRpcFault('Invalid JSON-RPC response', -32603); } } ?>
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to