[英]AWS $_POST is empty with REST API. Site is working fine
I am working on REST APIs of cakephp
. 我正在使用cakephp
REST API。 All working good on my localhost. 在我的本地主机上一切正常。 When I transfer code to live server which is AWS EC2 Ubuntu
machine suddenly all stop working. 当我将代码传输到实时服务器(即AWS EC2 Ubuntu
计算机)时,所有设备突然停止工作。 While my site is working fine. 虽然我的网站工作正常。
on debug I found that $_POST
is empty. 在调试时,我发现$_POST
为空。
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 我在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 并在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. 需要帮助请叫我。
You can use file_get_contents('php://input') for taking data from AJAX request. 您可以使用file_get_contents('php:// input')从AJAX请求中获取数据。 But if you want to send data from POSTMAN then you need to use $_POST to take that data. 但是,如果要从POSTMAN发送数据,则需要使用$ _POST接收该数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.