Google Cloud Pub/Sub Push Messages - Empty POST

你说的曾经没有我的故事 提交于 2019-11-28 11:59:03

问题


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:


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.



来源:https://stackoverflow.com/questions/51331722/google-cloud-pub-sub-push-messages-empty-post

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