[英]Google Cloud Pub/Sub Push Messages - Empty POST
I currently have successfully set up a topic and subscription in the google cloud platform, and have verified my site with google and added the domain to the GCP. 我目前已经在Google云平台上成功设置了主题和订阅,并已使用Google验证了我的网站并将该域添加到GCP中。
Whenever I try to send a test message from https://console.cloud.google.com/cloudpubsub/topics/subscription_sync , the endpoint I configured receives something , but the POST variable is empty. 每当我尝试从发送测试信息https://console.cloud.google.com/cloudpubsub/topics/subscription_sync ,我配置端点收到的东西 ,但POST变量是空的。 Here is the code I have so far in php, it just does simple logging of the POST variable (which later shows up in my logs as empty.) 这是我到目前为止在php中拥有的代码,它只是对POST变量进行简单的记录(以后在我的日志中显示为空)。
require_once 'EventPersister.class.php';
$eventPersister = new EventPersister(EventPersister::GOOGLE_WEBHOOKS);
$eventPersister->Persist($_POST);
Is there anything special I need to do to get the POST data to show up properly? 为了使POST数据正确显示,我需要做些特殊的事情吗?
For anyone that's having trouble with this, it's because the POST data is sent in a json format. 对于任何对此有麻烦的人,这是因为POST数据是以json格式发送的。 So instead of looking at $_POST, you have to do 因此,您不必查看$ _POST,而必须执行
json_decode(file_get_contents('php://input'));
....and that should work. ....那应该可行。 Alternatively, you can do 或者,您可以
json_decode($HTTP_RAW_POST_DATA);
to get the data. 获取数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.