External POST data not arriving

I am trying to receive a webhook and when I read the Request object I receive the following:

yii\web\Request Object
(
[enableCsrfValidation] => 1
[csrfParam] => _csrf
[csrfCookie] => Array
(
[httpOnly] => 1
)

[enableCsrfCookie] => 1
[enableCookieValidation] => 1
[cookieValidationKey] => BmfVol8Cai27S6okl1yhZaXyeN452rJq
[methodParam] => _method
[parsers] => Array
    (
        [application/json] => yii\web\JsonParser
    )

[trustedHosts] => Array
    (
    )

[secureHeaders] => Array
    (
        [0] => X-Forwarded-For
        [1] => X-Forwarded-Host
        [2] => X-Forwarded-Proto
        [3] => Front-End-Https
        [4] => X-Rewrite-Url
    )

[ipHeaders] => Array
    (
        [0] => X-Forwarded-For
    )

[secureProtocolHeaders] => Array
    (
        [X-Forwarded-Proto] => Array
            (
                [0] => https
            )
        [Front-End-Https] => Array
            (
                [0] => on
            )
    )

[_cookies:yii\web\Request:private] => 
[_headers:yii\web\Request:private] => yii\web\HeaderCollection Object
    (
        [_headers:yii\web\HeaderCollection:private] => Array
            (
                [host] => Array
                    (
                        [0] => mydomain.com
                    )
                [connection] => Array
                    (
                        [0] => Keep-Alive
                    )
                [accept-encoding] => Array
                    (
                        [0] => gzip
                    )
                [cf-ipcountry] => Array
                    (
                        [0] => US
                    )
                [cf-ray] => Array
                    (
                        [0] => 469d6e8688a0bb72-SEA
                    )
                [cf-visitor] => Array
                    (
                        [0] => {"scheme":"https"}
                    )
                [accept] => Array
                    (
                        [0] => application/json, text/plain, */*
                    )
                [user-agent] => Array
                    (
                        [0] => axios/0.16.2
                    )
                [cf-connecting-ip] => Array
                    (
                        [0] => 52.38.35.201
                    )
            )
    )

[_rawBody:yii\web\Request:private] => 
[_bodyParams:yii\web\Request:private] => 
[_queryParams:yii\web\Request:private] => 
[_hostInfo:yii\web\Request:private] => 
[_hostName:yii\web\Request:private] => 
[_baseUrl:yii\web\Request:private] => 
[_scriptUrl:yii\web\Request:private] => /index.php
[_scriptFile:yii\web\Request:private] => 
[_pathInfo:yii\web\Request:private] => site/webhook
[_url:yii\web\Request:private] => /site/webhook
[_port:yii\web\Request:private] => 
[_securePort:yii\web\Request:private] => 
[_contentTypes:yii\web\Request:private] => 
[_languages:yii\web\Request:private] => 
[_csrfToken:yii\web\Request:private] => 
[_isConsoleRequest:yii\base\Request:private] => 
[_events:yii\base\Component:private] => Array
    (
    )
[_eventWildcards:yii\base\Component:private] => Array
    (
    )
[_behaviors:yii\base\Component:private] => 
[_scriptFile:yii\base\Request:private] => 

)

I have disabled the csrf in the beforeAction function but it appears it is still active in this object. Also there doesn’t appear to be any POST data.

Any suggestions?

Thanks.

Turn off CSRF-validation for that endpoint: https://github.com/samdark/yii2-cookbook/blob/master/book/incoming-post.md

I have done that:

public function beforeAction($action)
{
	if (in_array($action->id, ['webhook'])) {
        $this->enableCsrfValidation = false;
    }
	
    return parent::beforeAction($action);
}

And here is my action:

public function actionWebhook()
{
    $this->layout = false;
	$request = Yii::$app->request;
	file_put_contents('eventdata.txt', print_r($request, true), FILE_APPEND);
	
	return;
}

I figured out what was going on with the missing POST data. When htaccess was redirecting to an HTTPS url the POST data was not being included in the redirect. I just ended up changing my webhook to use the https version and it started working.

1 Like