I searched all of stackoverflow and google to solve my problem.
I created two projects with Zend Framework - Project1 and Project2 - and I want to implement web services on one of them. The idea is to send a JSON string to Project1 and get back JSON with all the information associated with this variable using POST. Now I created a TestController on Project2 :
public function indexAction(){ $uri = 'http://project1.com/WebService/data'; $config = array( 'adapter' => 'Zend_Http_Client_Adapter_Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => true), ); $client = new Zend_Http_Client($uri, $config); $request = $client->request('POST'); print_r($request->getBody()); exit(); }
The above code works. It reads dataAction from the dataAction controller and gives me the output of what the echo is. But when I try this:
public function indexAction(){ $uri = 'http://project1.com/WebService/data'; $config = array( 'adapter' => 'Zend_Http_Client_Adapter_Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => true), ); $client = new Zend_Http_Client($uri, $config); $data = array( 'userID' => 'TEST TEST', 'value' => 1, 'description' => 'ABCDEFG', ); $request = $client->request('POST'); $json = json_encode($data); $client->setRawData($json, 'application/json')->request('POST'); exit(); }
And on the server side, when I try to display inside the dataAction :
public function dataAction(){ var_dump($this->getRequest()->getParam('var-name')); var_dump($_POST); die(); }
I get the output of this: NULL array (0) {} .... I get the same result when I try it on the client side. Also mention .. I also tried to open the php: // file, but got an empty line ...
What am I missing ??? I disappointed myself in the search in the morning, but did not get a solution.
Thanks in advance for your reply.