dongzhi7641 2015-12-10 09:29
浏览 40

使用REST API,AWS $ _POST为空。 网站工作正常

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

enter image description here

let me know if you need any thing else.

  • 写回答

1条回答 默认 最新

  • duanjiong1952 2015-12-10 14:19
    关注

    You can use file_get_contents('php://input') for taking data from AJAX request. But if you want to send data from POSTMAN then you need to use $_POST to take that data.

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测