Yii 1动作没有从 Postman 那里得到$_POST

3bygqnnd  于 2022-11-09  发布在  Postman
关注(0)|答案(1)|浏览(196)

我正在使用Yii 1,测试一个我正在开发的API,当我POST到这个URL时
https://blabla.com/products/report/notification
我在postman上什么都没得到
我的筛选器

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

我的行动是

public function actionnotification() {

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

该URL是正确的,如果在上面的操作中i echo 'hi';,则它会回显hi。
我的规矩是

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

这是我从postman导出的cURL

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'

当我把它改成params and GET时,它能工作,但是POST, body x-www-form-urlencodedGET, body x-www-form-urlencoded不能工作,是不是我遗漏了什么?谢谢

e0uiprwp

e0uiprwp1#

尝试在主体中发送POST数据。我通常使用Yii方法代替$_POST或$_GET:https://www.yiiframework.com/doc/guide/2.0/en/runtime-requests

**编辑:**下面是我的 Postman 配置,用于发送POST请求postman
**Edit 2:**在您的配置文件中,您应该向组件/请求添加一个名为enableCsrfValidation的属性,并将其设置为false。我将保留我的属性:

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

相关问题