Пытаюсь получить обновления от бота Telegram с помощью запроса на публикацию:
POST https://api.telegram.org/bot/getUpdates
Это отлично работает в Postman, я получаю ответ от бота:
{
"ok": true,
"result": [
{
"update_id": 22720266,
"message": {
"message_id": 25,
"from": {
"id": 67825600,
"is_bot": false,
... (etc) ...
Но когда я пытаюсь отправить тот же запрос из моего HTTP-клиента C++ Boost, я получаю следующую ошибку:
HTTP/1.1 400 Bad Request
Server: nginx/1.18.0
Date: Thu, 16 Jan 2025 12:52:52 GMT
Content-Type: text/html
Content-Length: 157
Connection: close
400 Bad Request
400 Bad Request
nginx/1.18.0
Я попробовал несколько методов отправки запроса, в основном из примеров повышения, таких как https://www.boost.org/doc/libs/master/l ... mple/http/ client/async/http_client_async.cpp
и
https://www.boost.org/doc/libs/1_84_0/l ... nc_ssl.cpp
Здесь это код, который я изменил для версии http (без SSL):
int main(int argc, char** argv)
{
//POST https://api.telegram.org/bot/getUpdates
auto const host = "https://api.telegram.org";
auto const port = "80";
auto const target = "/bot/getUpdates";
int version = 11;
// The io_context is required for all I/O
net::io_context ioc;
// Launch the asynchronous operation
std::make_shared(ioc)->run(host, port, target, version);
// Run the I/O service. The call will return when
// the get operation is complete.
ioc.run();
return EXIT_SUCCESS;
}
И формируем запрос:
// Start the asynchronous operation
void run(char const* host, char const* port, char const* target, int version) {
// Set up an HTTP POST:
req_.version(version);
req_.method(http::verb::post);
req_.target(target);
req_.set(http::field::host, host);
req_.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);
req_.set(http::field::content_type, "application/json");
req_.content_length(0);
// Look up the domain name
resolver_.async_resolve(
host,
port,
beast::bind_front_handler(
&session::on_resolve,
shared_from_this()));
}
Для версии SSL я делаю практически то же самое, за исключением использования порта 443. Рукопожатие завершается нормально,stream.handshake(ssl::stream_base::client);
code>
но затем я получаю тот же ответ с «неверным запросом»:
HTTP/1.1 400 Bad Request
Server: nginx/1.18.0
Спасибо за советы, как это исправить!
p.s. Дополнительная информация:
вывод https-запроса, который я отправляю с помощью boost:
-> Sending Request:
POST /bot7451143435:AAHFx0dLp6sB2ifaDNQRnUcMwKGtQdZEgio/getUpdates HTTP/1.1
Host: https://api.telegram.org
User-Agent: Boost.Beast/322
=== Request sent ===
(response: )
HTTP/1.1 400 Bad Request
Server: nginx/1.18.0
...
Подробнее здесь: https://stackoverflow.com/questions/793 ... oost-beast
Ошибка в запросе getUpdates к боту Telegram, использующему Boost Beast ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как присоединиться к моему боту Telegram к общедоступному каналу [закрыто]
Anonymous » » в форуме Python - 0 Ответы
- 11 Просмотры
-
Последнее сообщение Anonymous
-