Yii1 action doesn't get $_POST from postman

585 views Asked by At

I'm using Yii 1, and testing an API i'm working on, and when i POST to this URL

https://blabla.com/products/report/notification

I get nothing on postman

My Filters

public function filters()
    {
        return array(
            'accessControl', // perform access control for CRUD operations
            'postOnly + delete', // we only allow deletion via POST request
        );
    }

My action is

public function actionnotification() {

        print_r($_POST);
        // print_r(Yii::app()->request->getPost('report_id')); //this didn't work either
        die;
}

the URL is correct, and if i echo 'hi'; in the action above, it does echo hi.

and my rules are

public function accessRules()
    {
        return array(
            array('allow',  // allow all users to perform 'index' and 'view' actions
                'actions'=>array('notification'),
                'users'=>array('*'),
            );
     }

Here is my exported cURL from postman

curl -X POST \
  https://blabla.com/products/report/notification \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Cookie: PHPSESSID=puevhejh61fg4f0qtc52nbg3jm' \
  -H 'Postman-Token: 4fb0526b-f26e-4802-bf13-8361f65a26af,b610902b-25f1-4eb9-9ce6-cfddec164788' \
  -H 'Referer: https://blabla.com/products/report/notification' \
  -H 'User-Agent: PostmanRuntime/7.18.0' \
  -H 'cache-control: no-cache' \
  -d 'report_id=123131231&status_id=1'

When i change it to a params and GET it works, but POST, body x-www-form-urlencoded and a GET, body x-www-form-urlencoded doesn't work, is there something I'm missing here? Thank you

1

There are 1 answers

5
user3502640 On

Try sending the POST data in the body instead. I usually use Yii methods instead of $_POST or $_GET: https://www.yiiframework.com/doc/guide/2.0/en/runtime-requests

Edit: Here's my postman configuration for sending POST requests postman

Edit2: In your config file, you should add to components/requests a property named enableCsrfValidation and set it to false. I'll leave you mine:

'components' => [
    'request' => [
        'cookieValidationKey' => {key},
        'enableCsrfValidation' => false
    ],
...