[PHP] Question about php://input
- Date: Sat, 13 Feb 2016 20:32:05 -0600
- From: Anthony Papillion <anthony@xxxxxxxxxxxxxxx>
- Subject: [PHP] Question about php://input
-----BEGIN PGP SIGNED MESSAGE-----
I'm writing a bot for the Telegram instant messaging platform. In all
of the tutorials, I see people using the php://input stream as a way
to get data being sent from the Telegram server (JSON formatted which
is then converted into an array for use). For some reason, I'm can't
seem to get at that data.
Here's the flow: when a user sends my bot a message through Telegram,
the platform calls a script on my server and tells the script things
about the message like chat_id, message_text, etc. When the script is
first called, I have this code
$request = file_get_contents("php://input");
run to grab the incoming data. Then, I transform that data into an
array by running:
$requestArray = json_decode($request, true);
Now, according to everyone I've read, I should be able to get a
variable called "chat_id" by doing this:
$chat_id = $requestArray["result"]["message"]["chat"]["id"];
However, it seems like NONE of the expected variables are actually
there! I've checked the API and it seems like I'm calling it right.
When I try to use that data in a response call like:
I am told it is a bad request (in the Apache logs.
Can anyone tell me how to view what's actually coming in to the
php://input from the remote server?
-----BEGIN PGP SIGNATURE-----
-----END PGP SIGNATURE-----
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php