getting error in rest api client

For programming and general questions on Zend Framework
Post Reply
Posts: 6
Joined: Wed Oct 27, 2010 11:53 am

getting error in rest api client

Post by happysidhu » Mon Apr 30, 2012 6:22 pm

i'm trying to do below client accessing

Code: Select all

require_once 'Zend/Rest/Client.php';
$client = new Zend_Rest_Client('http://zf.localhost/api.php');

echo '<pre>';
echo '</pre>';
here rest server code

Code: Select all

public function updatePage($apiKey, $id, $name, $headline, $description, $content)
    if(!$this->_validateKey($apiKey)) {
        return array('error' => 'invalid api key', 'status' => false);
    // open the page
    $itemPage = new CMS_Content_Item_Page($id);
    // update it
    $itemPage->name = $name;
    $itemPage->headline = $headline;
    $itemPage->description = $description;
    $itemPage->content = $content;
    // save the content item
    // return the page as an array, which Zend_Rest will convert into the XML response
    return $itemPage->toArray();
when i access above client code i get below error

Code: Select all

Fatal error:  Uncaught exception 'Zend_Rest_Client_Result_Exception' with message 'REST Response Error: simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]:       ^' in C:\xampp\htdocs\owned\zf\library\Zend\Rest\Client\Result.php:61
Stack trace:
#0 C:\xampp\htdocs\owned\zf\library\Zend\Rest\Client.php(236): Zend_Rest_Client_Result->__construct(' <?xml version=...')
#1 C:\xampp\htdocs\owned\yuldi\test.php(14): Zend_Rest_Client->__call('get', Array)
#2 C:\xampp\htdocs\owned\yuldi\test.php(14): Zend_Rest_Client->get()
#3 {main}
  thrown in C:\xampp\htdocs\owned\zf\library\Zend\Rest\Client\Result.php on line 61
Please help me how to fix this.

Posts: 6
Joined: Wed Oct 27, 2010 11:53 am

need rest api help

Post by happysidhu » Tue May 08, 2012 6:09 pm

please help

User avatar
Posts: 88
Joined: Tue Jan 10, 2012 2:41 pm

Re: getting error in rest api client

Post by mkherlakian_zend » Tue May 08, 2012 7:06 pm

From the info you have posted it looks like part of your output needs encoding, simple_xml_string() can't load it, or there's some foreign output you don't necessarily see (and that you don't want) that ends up in the array.

I would however suggest you use Zend_Rest_Controller instead on Zend_Rest_Server as it is newer and more flexible: ... controller

and an example tutorial: ... -framework

Post Reply