天天看点

yii2 使用raw http request

Parses a raw HTTP request using ​​yii\helpers\Json::decode()​​

To enable parsing for JSON requests you can configure ​​yii\web\Request::$parsers​​ using this class:

'request' => [
    'parsers' => [
        'application/json' => 'yii\web\JsonParser',
    ]
]      

1、将以上配置添加到main.php 中的 components数组里面

2、用postman模拟

header头传参数: Content-Type: application/json