Google Cloud Platform发布/订阅推送空POST数据 [英] Google Cloud Platform Pub/Sub push empty POST data

查看:143
本文介绍了Google Cloud Platform发布/订阅推送空POST数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在云平台GUI中发送消息时(即,主题->在相同的问题,但是

json_decode($HTTP_RAW_POST_DATA);

什么也没做.我也尝试过

$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;

推送端点URL中的

.一样.空的.因此,似乎POST主体为空,我不知道为什么.谁能帮助我指出正确的方向?

解决方案

$HTTP_RAW_POST_DATAcloud 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?

解决方案

$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'));

这篇关于Google Cloud Platform发布/订阅推送空POST数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆