简体   繁体   English

Google Cloud Platform发布/订阅推送空POST数据

[英]Google Cloud Platform Pub/Sub push empty POST data

When I try to send a message in the cloud platform GUI (ie topic -> publish message on the cloud platform topic page ) my endpoint PHP script is triggered, but the POST data is empty. 当我尝试在云平台GUI中发送消息时(即,主题->在云平台主题页面上发布消息),我的端点PHP脚本被触发,但是POST数据为空。

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. 在推送端点URL中。 Same thing. 一样。 Empty. 空。 So it seems that the POST body is empty and I can't figure out why. 因此,似乎POST正文为空,我不知道为什么。 Can anyone help point me in the right direction? 谁能帮助我指出正确的方向?

$HTTP_RAW_POST_DATA was removed in PHP7 even in earlier verisons, it required always_populate_raw_post_data in php.ini. $HTTP_RAW_POST_DATA 在PHP7中甚至在较早的版本中也已删除 ,它在php.ini中需要always_populate_raw_post_data As the answer you linked says, $_POST will not work. 正如您链接的答案所言, $_POST将不起作用。

Instead use: 而是使用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM