Google Cloud Pub/Sub Push Messages - Empty POST

2019-03-04 16:14发布

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.

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. 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.)

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?

1条回答
Evening l夕情丶
2楼-- · 2019-03-04 16:41

For anyone that's having trouble with this, it's because the POST data is sent in a json format. So instead of looking at $_POST, you have to do

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.

查看更多
登录 后发表回答