Question about php://input

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hi Everyone,

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"][0]["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:

file_get_contents("https://api.telegram.org/my_token/sendMessage?chat_id=".$chat_id;

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?

Thanks!
Anthony
-----BEGIN PGP SIGNATURE-----

iQIcBAEBCgAGBQJWv+ckAAoJEAKK33RTsEsV8y4QAIXQlGLQ96MPla7QMtIj2Rql
Wil1GhbotbqjBzCzizzCE0qZRQgz1zd5WzY+TPqArTBiIgAhgrbRP7gQg088zfIw
Vlzp9ZUeWmnn0ko1uGJeorXEzEkCa0Lj6padBIuPFABM+clbueYTpLFSjr5UNDRp
p17hNyFqnWNrEgy6YT45tti9qi7zgn65igVOdbNusGKnFW+aCVgQrWxc2HcgABnQ
RwpQZyXAzOPpgvJDscx6J5yE1eYrw7Iobf5dx8jksc0Af2Htk7bn1j+o5e1Sul5z
CzaDf8H8bANmglEBAtoVbGeT5n6oYZ6zFMKTh7cNmbXXcidl4ptlr+QXloxn/++U
ZjPT85lNRZZzzuC7tNUrR+DZd7sa9vMd1DxBXp4AgvQSFvegjPwznJFvLesgD9i3
h1MBVV9wPdKEEqnS+4OSJqkPSMJ53tMJBplthOG0kE1PbEzIIH97oKgzZTS8pVRW
kqD8FhuHoVsq/WScuFJBmA8qt0s8TqcbKMTP+zqmzi2M1ghGNOWcJqp4qACJqxLL
UuoyMD3cfeDrUSP4Kim6i5+GejHBa81t/JoFmLQO34rNAezQDFXkJrwGPyrw+slH
hIvJTKwPNUHXFKM2KQRtOHOjMSi8sLZlMUdmnITgMWp39JarhR88ud6zb+KUVQEI
Ex8eJ5sotD3IGvuCHjLt
=rBA2
-----END PGP SIGNATURE-----


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux