-
-
$base_url = 'http://bbs.it-home.org/'; - $client = new Zend_Rest_Client($base_url);
- // Set global variables
$headers = array();
$client->headers($headers);
// Remote call, call sayHello interface, pass two string parameters
- $response = $client->sayHello('Hello', 'world!')->get();
if ($this->_request->getParam('debug')) {
- echo "
";</li>
<li> print_r(json_decode($response, 1));</li>
<li> echo " ";
- } else {
- echo $response;
- }
-
-
Copy code
Server side:
-
-
// Capture request header information - $headers = $this->_request->getParam('headers');
- Zend_Registry::set('headers ', $headers);
-
- $server = new Zend_Rest_Server();
- $server->setClass('Lijiabeibei_Blog');
- $server->handle();
/ /Interface processing class: (Lijiabeibei_Blog)
- class Lijiabeibei_Blog {
- protected $retval = array();
function __construct() {
-
- }
/ **
- * Test interface
- * @param string $a
- * @param string $b
- */
- function sayHello($a, $b) {
- if (!$this->retval['success']) {
- $this->retval['debug']= print_r(
- Zend_Registry::get('headers'), 1
- );
- return json_encode($this->retval);
- }
- $this->retval['debug'] = $a .' '.$b ;
return json_encode($this->retval);
- }
- }
-
Copy code
If you want to set up multiple service classes, you can do this :
$server = new Ylili_Rest_Server();
$server->setClass('Lijiabeibei_Blog');
$server->setClass('Lijiabeibei_Shop);
Note that the method naming of multiple server classes should not conflict.
|