A
A
Alexey Sklyarov2019-02-01 19:16:20
Laravel
Alexey Sklyarov, 2019-02-01 19:16:20

Why does a POST API request return the html code of the page?

I'm trying to set up a telegram bot. I am using php-telegram-bot in laravel project. I hung up a webhook using a certificate, I run: https://api.telegram.org/....../getWebhookInfo, an error is generated:

{
"ok": true,
"result": {
"url": "https://..../api/telegram/hook/",
"has_custom_certificate": true,
"pending_update_count": 14,
"last_error_date": 1549036967,
"last_error_message": "Wrong response from the webhook: 301 Moved Permanently",
"max_connections": 40
}
}

I can't figure out what the problem is?
I started to check: there are redirect requests from http to https, requests are specified in the router only by post. I send a post request through Postman with the message=test parameter, the html code of the page is returned in the response.
The controller method itself:
public function hook()
    {
      $commands_paths = [
            app_path() . '/Telegram/Bots/Bitbd_BOT/Commands',
      ];
      try {
          // Create Telegram API object
          $telegram = new Telegram($this->bot_api_key, $this->bot_username);
          TelegramLog::initErrorLog(storage_path() . "/{$this->bot_username}_error.log");
          TelegramLog::initDebugLog(storage_path() . "/{$this->bot_username}_debug.log");
          TelegramLog::initUpdateLog(storage_path() . "/{$this->bot_username}_update.log");
          // Add commands paths containing your custom commands
          $telegram->addCommandsPaths($commands_paths);
          $telegram->enableLimiter();
          // Handle telegram webhook request
          $telegram->handle();

      } catch (TelegramException $e) {
            echo $e->getMessage();
      }
    }

Routes:
Route::group(['prefix' => 'telegram'], function () {
    Route::any('hook/set', '[email protected]');
    Route::post('hook','[email protected]');
});

If you write: , then you can open the page from the browser, get a response that the transmitted data is empty, and the request through Postman also normally receives a response. What could be the reason? Route::get('hook','[email protected]');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kylin, 2019-02-01
@palkan_karabov

And in the answer it is casual not Exception?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question