I have been searching all over stackoverflow and Google for a solution to my problem.
I have 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 receive back a JSON with all the details associated with that variable using POST. Now I have 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 the dataAction
from the Project1
controller and gives me an output of whatever is echoed. 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 displaying inside dataAction
:
public function dataAction(){
var_dump($this->getRequest()->getParam('var-name'));
var_dump($_POST);
die();
}
I get an output of this: NULL array(0) { } .... I get the same output when I try it on the client side. Also to mention.. I also tried opening the php://input file but got an empty string...
What am I missing??? I have frustrated myself searching on it since morning but got no solution.
Thanks in advance for response.