I am working on REST APIs of cakephp
. All working good on my localhost. When I transfer code to live server which is AWS EC2 Ubuntu
machine suddenly all stop working. While my site is working fine.
on debug I found that $_POST
is empty.
here is my code
public function add() { //die('dsafs');
$this->autoRender = false;
$this->layout = false;
// $this->loadModel('User');
$entityBody = file_get_contents('php://input');
pr($entityBody);
if ($this->request->is('post')) {
$this->User->set($this->request->data);
if ($this->User->validates($this->request->data)) {
if ($this->User->saveAll($this->request->data)) {
$response = array('status' => 'success', 'message' => 'Thank you for registering with us. Please check your e-mail inbox as your e-mail confirmation has just been sent.');
} else {
$response = array('status' => 'failed', 'message' => 'There might be some error. Please try again');
}
} else {
$response = array('status' => 'failed', 'message' => array_values($this->User->validationErrors));
}
echo str_replace(array('[', ']'), '', htmlspecialchars(json_encode($response), ENT_NOQUOTES));
// print_r($response);
}else{
echo "you are not authorised";
}
exit();
}
I allowed my controller in AppController.php
function beforeFilter() {
//pr($this->params);die;
if (in_array($this->params['controller'], array('api'))) {
// For RESTful web service requests, we check the name of our contoller
$this->Auth->allow();
// this line should always be there to ensure that all rest calls are secure
// $this->Security->requireSecure();
// $this->Security->unlockedActions = array('edit', 'delete', 'add', 'view');
} else {
$this->_defaultSettings();
}
}
and add routing too in routes.php
Router::mapResources('api');
Router::parseExtensions();
Below is the response I am getting.
<pre></pre>you are not authorised
let me know if you need any thing else.