Google Cloud Platform Pub/Sub push empty POST data

 ̄綄美尐妖づ 提交于 2019-12-11 17:22:46

问题


When I try to send a message in the cloud platform GUI (i.e. topic -> publish message on the cloud platform topic page) my endpoint PHP script is triggered, but the POST data is empty.

So all the permissions and domain verifications are in place. The topic and subscription both seem to be correct.

I found this same question here but

json_decode($HTTP_RAW_POST_DATA);

did nothing. I also tried

$content = null;
foreach( $_POST as $k => $v ){
// Just to see what any possible data might be
    $content .= "Key: $k, Value: $v\n";
}
$file = fopen( __DIR__ . '/log.txt', 'w') or die( 'Unable to open file!' );
fwrite( $file, $content );
fclose( $file );
return;

in the push endpoint URL. Same thing. Empty. So it seems that the POST body is empty and I can't figure out why. Can anyone help point me in the right direction?


回答1:


$HTTP_RAW_POST_DATA was removed in PHP7 even in earlier verisons, it required always_populate_raw_post_data in php.ini. As the answer you linked says, $_POST will not work.

Instead use:

json_decode(file_get_contents('php://input'));


来源:https://stackoverflow.com/questions/52616355/google-cloud-platform-pub-sub-push-empty-post-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!