<p>Full disclosure: I'm <a href="http://www.blockcypher.com/" rel="nofollow">BlockCypher's</a> Developer Advocate. </p>

<p>I'm not a PHP expert, but I know a number of our customers have had issues reading return data from PHP. This thread on Stack Overflow might help:</p>

<p><a href="https://stackoverflow.com/questions/8945879/how-to-get-body-of-a-post-in-php">https://stackoverflow.com/questions/8945879/how-to-get-body-of-a-post-in-php</a></p>

CC BY-SA 3.0
2015-08-14T18:28:33.523Z
2015-08-14T18:28:33.523Z
Josh Cincinnati
<p>I've been trying to get this to work for the past 3 days and I've all but given up on it. Basically, I've used requestb.in to monitor if any POST requests are going through; requestb.in always displays a response. However, I can't replicate this on my own website. </p>

<p>I simply can't find a way to read the body of the response that's getting called back to my server. </p>

<p>For reference, I'm using this sample provided by BlockCypher:</p>

<pre><code> require __DIR__ . '/../bootstrap.php';

$webHook = new \BlockCypher\Api\WebHook();
$webHook-&gt;setUrl("http://mysite.com/dev/data/index.php");
$webHook-&gt;setEvent('unconfirmed-tx');

/// For Sample Purposes Only.
$request = clone $webHook;

$webHookClient = new \BlockCypher\Client\WebHookClient($apiContexts['BTC.main']);

/// Create WebHook
try {
    $output = $webHookClient-&gt;create($webHook);
} catch (Exception $ex) {
    ResultPrinter::printError("Created WebHook", "WebHook", null, $request, $ex);
    exit(1);
}

ResultPrinter::printResult("Created WebHook", "WebHook", $output-&gt;getId(), $request, $output);

return $output;
</code></pre>

<p>I had tested the callback url using requestb.in: </p>

<pre><code>http://requestb.in/zphhv1zp?inspect
</code></pre>

<p>I've been going crazy testing everything I could find online, but nothing really helped me out. What should I be using to retrieve the POST data?</p>

<p>PS: this is the code that I've been testing most recently
</p>

<pre><code>&lt;html lang="en"&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;?php
        $url = "http://requestb.in/zphhv1zp";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $data = curl_exec($ch);
        curl_close($ch);
        echo $data;

        // $inputJSON = file_get_contents('');
        // $input = json_decode( $inputJSON, TRUE );
        // echo $input['hash'];
    ?&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

CC BY-SA 3.0
2015-08-14T00:14:50.943Z
While you're showing the code you're using to create the webhook, you're not showing how you're reading the data getting posted by BlockCypher. In PHP $_POST is only valid for forms, while the data BlockCypher POSTs is a JSON document. To access the body of a regular POST (non-form) in PHP use file_get_contents('php://input').
Matthieu
CC BY-SA 3.0
2015-08-14T13:37:28.987Z
@Matthieu thank you for your reply. I've seen that approach and I've tried to implement it to no avail. For some reason php://input didn't return anything, which shouldn't be the case since I know for a fact that the webhook is POSTing data to my callback url.
robbythebobby
<blockchain><php>
How to handle POST data sent from Blockcypher WebHook API
robbythebobby
# How to handle POST data sent from Blockcypher WebHook API

(Asked by: username_0 on 2015-08-13)

I've been trying to get this to work for the past 3 days and I've all but given up on it. Basically, I've used requestb.in to monitor if any POST requests are going through; requestb.in always displays a response. However, I can't replicate this on my own website. 
I simply can't find a way to read the body of the response that's getting called back to my server. 
For reference, I'm using this sample provided by BlockCypher:
 require __DIR__ . '/../bootstrap.php';

$webHook = new \BlockCypher\Api\WebHook();
$webHook->setUrl("http://mysite.com/dev/data/index.php");
$webHook->setEvent('unconfirmed-tx');

/// For Sample Purposes Only.
$request = clone $webHook;

$webHookClient = new \BlockCypher\Client\WebHookClient($apiContexts['BTC.main']);

/// Create WebHook
try {
    $output = $webHookClient->create($webHook);
} catch (Exception $ex) {
    ResultPrinter::printError("Created WebHook", "WebHook", null, $request, $ex);
    exit(1);
}

ResultPrinter::printResult("Created WebHook", "WebHook", $output->getId(), $request, $output);

return $output;

I had tested the callback url using requestb.in: 
http://requestb.in/zphhv1zp?inspect

I've been going crazy testing everything I could find online, but nothing really helped me out. What should I be using to retrieve the POST data?
PS: this is the code that I've been testing most recently

**Tags:** blockchain, php

> **Comments:**
> **username_1**: While you're showing the code you're using to create the webhook, you're not showing how you're reading the data getting posted by BlockCypher. In PHP $_POST is only valid for forms, while the data BlockCypher POSTs is a JSON document. To access the body of a regular POST (non-form) in PHP use file_get_contents('php://input').  
> **username_0**: @username_1 thank you for your reply. I've seen that approach and I've tried to implement it to no avail. For some reason php://input didn't return anything, which shouldn't be the case since I know for a fact that the webhook is POSTing data to my callback url.  

---

## 1 answers

### Answer by username_2 on 2015-08-14. Score: 1 | Accepted answer

Full disclosure: I'm [BlockCypher's](http://www.blockcypher.com/) Developer Advocate.

I'm not a PHP expert, but I know a number of our customers have had issues reading return data from PHP. This thread on Stack Overflow might help:

<https://stackoverflow.com/questions/8945879/how-to-get-body-of-a-post-in-php>


---

