How to read data sent by webhooks?

2019-02-16 04:49发布

问题:

I have the latest woocommerce plugin, and I have to set a webhook to one of my URL. But I am not able to read it in my $_REQUEST and nor in $input = file_get_contents("php://input");.

回答1:

$webhookContent = "";

$webhook = fopen('php://input' , 'rb');
while (!feof($webhook)) {
    $webhookContent .= fread($webhook, 4096);
}
fclose($webhook);
mail('mail@yourdomain.com', 'test - hook', $webhookContent);

This is all it took. It will send all the body to your email