Telegram + PHP (Windows 7): Could not open stream: HTTP request failed! HTTP / 1.1 404 not found

I am trying to transfer my first steps to Telegram, and I am also new to PHP ......

I configured Apache 2.4 with PHP 5.6.14 and SSL on my Windows 7 PC and it works fine in http and https.

Then I tried to complete this telegram tutorial https://www.youtube.com/watch?v=hJBYojK7DO4 . Everything works fine until I create a simple PHP program like this

<?php
  $botToken = "<my_bot_token>";
  $website = "https://api.telegram.org/bot".$botToken; 
  $update = file_get_contents($website."/getUpates"); 
  print_r($update);
?>

When I try to put in my browser

https://localhost/Telegram/MyYouTubeTutorialBot/YouTubeTutorialBot.php

answer

Warning: file_get_contents(https://api.telegram.org/<my_bot_token>/getupates): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in <my_php_file_location> on line 6

I searched the Internet for similar problems, but I didn’t solve anything: the most interesting answer in this question is file_get_contents - could not open the stream: the HTTP request failed! HTTP / 1.1 404 not found , but I don’t understand how to adapt it to my business.

, file_get_contents.

, PHP, - -... bu ,

?

ADDED

, @aeryaguzov ....

, ...

<?php
  $botToken = "<my_bot_token>";
  $website = "https://api.telegram.org/bot".$botToken; 
  $update = file_get_contents($website."/getUpdates"); 
  print_r($update);
?>
+4
3

PHP . , https://api.telegram.org/<my_bot_token>/getupates .

+2

API Telegram - . JSON ok, false, a error_code a description. , , file_get_content() . , :

<?php
    $stream_context = stream_context_create(array(
        'http' => array (
            'ignore_errors' => true
         )
    ));

    $botToken = "<my_bot_token>";
    $website = "https://api.telegram.org/bot".$botToken;
    $update = file_get_contents($website."/getUpdates", false, $stream_context);
    print_r($update);
?>
0

. JSON, - , -

{"ok":false,"error_code":409,"description":"Conflict: can't use getUpdates method while webhook is active"}

- -API, ..... /setwebhook URL.

-1

Source: https://habr.com/ru/post/1613165/


All Articles