Possible Duplicate:
PHP php://input vs $_POST
I’m using the Facebook Real-time updates API to subscribe to changes. The docs state:
Following a successful subscription, Facebook will proceed to call your endpoint every time that there are changes (to the chosen fields or connections). For each update, it will make an HTTP POST request.
The request will have content type of
application/jsonand the body will comprise a JSON-encoded string containing one or more changes.
~ https://developers.facebook.com/docs/reference/api/realtime/
I tried over and over to access the POSTed data use $_POST, which was always empty. After googling for a while, i found this blog post which contained this magical line: $post_body = file_get_contents('php://input');.
I’ve never seen php://input before…. what is this? what does it do? What is Facebook doing on their side to create what I assume is a file with the JSON string in it? Why would they do this rather than sending it through $_POST?
php://input is a stream wrapper over raw input body. It’s parsed by php automatically so you could get
$_POSTin your code. If it doesn’t – this means that it is in an unexpected format.In the case of facebook – they send just a json string which isn’t what PHP interpreter expects there to be (it expects it to be a
key=val&key2=val&...string, and gets{key: "val",...}instead).That’s why you need to read and parse it manually.