douchen4915
2016-01-25 11:02
浏览 107
已采纳

从HTTP请求中获取JSON对象

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!

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doubu4826 2016-01-25 11:13
    已采纳

    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

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题