1

Folks I think I may miss a dead simple thing but I just have no idea where to look for it.

So I'm trying to implement block.io API to accept bitcoin payments on a website built on PHP. Now the Docs say that all notification events will use JSON objects pushed to my server through POST requests. So I decided to make a test BTC payment and log all requests on a specified URL to my DB. And here what I gen on dumping getallheaders()

{
["Content-Type"]=>
string(16) "application/json"
["User-Agent"]=>
string(12) "Block.io/0.1"
["Accept"]=>
string(10) "text/plain"
["Authorization"]=>
string(10) "Basic Og=="
["Connection"]=>
string(5) "close"
["Host"]=>
string(17) "site.com"
["Content-Length"]=>
string(3) "462" }

But dumping $_POST gives me an empty array. Dumping $_SERVER and $_GET gives nothing useful either. So my question is how can I find the JSON string declared in Content-Type?

Any suggestion would be helpful! Thanks!

peyeruni
  • 49
  • 5

1 Answers1

1

Because the Content-Type is application/json (not application/x-www-form-urlencoded) $inputJSON = file_get_contents('php://input');

EDIT: excellent explanation at PHP "php://input" vs $_POST

Community
  • 1
  • 1
C Würtz
  • 856
  • 9
  • 20
  • But could you please explain in plain words, why should I perform file_get_contents('php://input')? Because I'm pretty sure there are other noob coders like me out there :) – peyeruni Jan 25 '16 at 11:23
  • Sure. There is an excellent explanation at http://stackoverflow.com/questions/8893574/php-php-input-vs-post – C Würtz Jan 25 '16 at 12:54