How to communicate with JSON-RPC using php?
2 answers
There are a large number of ready-made implementations of both server and client parts of JSON RPC in PHP. For example, https://github.com/fguillot/JsonRPC .
A few more implementations are listed at https://en.wikipedia.org/wiki/JSON-RPC#Implementations . Or you can ask Google ( json rpc php implementation
).
|
What's the problem ? in general this is:
$sendData = array( 'p1' => 'v1', 'p2' => 'v2', .... ); function request($endPointUrlApi, $sendData) { $ch = curl_init($endPointUrlApi); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($sendData)); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); $out = curl_exec($ch); curl_close($ch); return json_decode($out, true); }
|