Yii仅在服务器上以发布方式未接收到数据

时间:2019-04-25 04:52:05

标签: php yii

创建了一个API终结点I,我将其作为邮递员的正文提交数据,但在服务器上它始终为空,而在localhost上运行良好。

请查看请求enter image description here

相同的请求可在localhost上运行,但不能在线运行。这是服务器端的代码,我正在使用Yii::$app->request->post()转储数据,这是该端点的完整代码。我曾尝试$_POST,$_REQUEST服务器上的每个请求都是空的

public function actionSocialcheck()
{
    $data = [];
    $model = new User();
    var_dump(Yii::$app->request->post());
    if ($model->load(Yii::$app->request->post(),'')) {
        $social = User::findBySocialLogin($model->socialLogin);
        if (empty($social)) {
            $data['status'] = self::API_OK;
            $data['check'] = false;
        } else {
            if (Yii::$app->request->post('role_id') != $social->role_id) {
                $data['error'] = \Yii::t('app', "You don't have permission to login as " . User::getRoleOptions($social->role_id));
                return $this->response = $data;
            }
            $data['error'] = \yii::t('app', "Social ID already exists.");
            $data['check'] = true;
            $data['status'] = self::API_OK;

            $data['detail'] =$social;
            $data['access-token'] = $social->access_token;
            // $usercl=new User();
            $loginarr = array(
                'device_name' => Yii::$app->request->post('device_name'),
                'device_token' => Yii::$app->request->post('device_token'),
                'device_type' => Yii::$app->request->post('device_type'),
                 );
            $data['login_detail']=$loginarr;

        }
    } else {
        $data['error'] = "Data not posted.";
    }
    $this->response = $data;
}

当我在本地服务器上尝试相同的请求时,它的输出正常 enter image description here

在这种情况下,您能帮我什么忙吗?谢谢

1 个答案:

答案 0 :(得分:-1)

public function actionSocialcheck(){

if(Yii::$app->request->isPost){
$data = [];
$social = User::findBySocialLogin(Yii::$app->request->post('socialLogin'));
if (empty($social)){
    $data['status'] = self::API_OK;
    $data['check'] = false;
}else{
       if (Yii::$app->request->post('role_id') != $social->role_id) {
            $data['error'] = \Yii::t('app', "You don't have permission to login as " . User::getRoleOptions($social->role_id));
            return $this->response = $data;
        }
        $data['error'] = \yii::t('app', "Social ID already exists.");
        $data['check'] = true;
        $data['status'] = self::API_OK;

        $data['detail'] =$social;
        $data['access-token'] = $social->access_token;
        $loginarr = array(
            'device_name' => Yii::$app->request->post('device_name'),
            'device_token' => Yii::$app->request->post('device_token'),
            'device_type' => Yii::$app->request->post('device_type'),
             );
        $data['login_detail']=$loginarr;
    }

}else {
    $data['error'] = "Data not posted.";
}
$this->response = $data;
}