Неверный запрос Binance 400 с использованием Boost::BeastC++

Программы на C++. Форум разработчиков
Anonymous
Неверный запрос Binance 400 с использованием Boost::Beast

Сообщение Anonymous »

Друзья, я понятия не имею, почему сервер Binance отвечает с ошибкой 400 при использовании библиотеки boost::beast. Я попробовал тот же http-запрос, используя openssl, и он работает нормально. Это ошибка, которую я получаю в консоли:

Код: Выделить всё

HTTP/1.1 400 Bad Request
Server: CloudFront
Date: Wed, 18 Sep 2024 15:26:48 GMT
Content-Type: text/html
Content-Length: 915
Connection: close
X-Cache: Error from cloudfront
Via: 1.1 c855d201fddbb6ef22989607fe8f5d1e.cloudfront.net (CloudFront)
X-Amz-Cf-Pop: VIE50-C2
X-Amz-Cf-Id: ckbq9NokUYRiAxcUFAfcYYG7CaE6v9xRx1sqlstwSuODrpbHGrA7Hg==



ERROR: The request could not be satisfied

400 ERROR
The request could not be satisfied.

Bad request.
We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.

If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.



Generated by cloudfront (CloudFront)
Request ID: ckbq9NokUYRiAxcUFAfcYYG7CaE6v9xRx1sqlstwSuODrpbHGrA7Hg==




А вот код, который я использую:

Код: Выделить всё

#include 
#include 
#include 
#include 
#include 

namespace beast = boost::beast;
namespace http = beast::http;
namespace net = boost::asio;
using tcp = boost::asio::ip::tcp;

void get_perpetual_btc_price() {
try {
// Set up the I/O context and stream
net::io_context ioc;
tcp::resolver resolver{ioc};
beast::tcp_stream stream{ioc};

// Resolve and connect
auto const results = resolver.resolve("api.binance.com", "443");
stream.connect(results);

// Prepare the HTTP GET request
http::request req{http::verb::get, "/api/v3/ticker/price?symbol=BTCUSDT", 11};
req.set(http::field::host, "api.binance.com");
req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);

// Send the request
http::write(stream, req);

// Prepare buffer and response object
beast::flat_buffer buffer;
http::response res;
beast::error_code ec;

// Read the response
http::read(stream, buffer, res, ec);

if (ec) {
throw beast::system_error{ec};
}

// Output the response
std::cout 

Подробнее здесь: [url]https://stackoverflow.com/questions/78999114/binance-400-bad-request-using-boostbeast[/url]

Вернуться в «C++»