body in the docs i am trying to send to the server : https://binance-docs.github.io/apidocs/spot/en/#order-book
// Start the asynchronous operation
void
run(
char const* host,
char const* port,
char const* target)
{
// Set SNI Hostname (many hosts need this to handshake successfully)
if(! SSL_set_tlsext_host_name(stream_.native_handle(), host))
{
beast::error_code ec{static_cast<int>(::ERR_get_error()), net::error::get_ssl_category()};
std::cerr << ec.message() << "\n";
return;
}
// Set up an HTTP GET request message
// req_.version(version);
req_.method(http::verb::get);
req_.target(target);
req_.set(http::field::host, host);
req_.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);
req_.body() = "symbol=btcusdt";
req_.prepare_payload(); // make HTTP 1.1 compliant
// Look up the domain name
resolver_.async_resolve(
host,
port,
beast::bind_front_handler(
&session::on_resolve,
shared_from_this()));
}
As you can see req_.body() = "symbol=btcusdt";
clearly not working(which i got from stackoverflow), is there another way to do it ? I dont want to use boost json for sending the body, maybe could use jsoncpp. please help me and advance thanks!
You didn't get that from StackOverflow. You did get:
Now if you somehow have an issue with that, you forgot to describe what the issue is.
As the commenter points out, it doesn't normally make sense to pass content with a GET request (background: HTTP GET with request body).
Checking the docs confirms it should be GET. So, then likely it expects query parameters. Poking at it with
"/api/v3/depth?symbol=btcusdt"
givesSo, yeah, it reads those.
"/api/v3/depth?symbol=BTCUSDT"
fixes the error:Proper Solution
You should add the query parameters. Beast doesn't have facilities for that:
So consider using something like e.g. Boost URL:
Where
make_url
is a convenience wrapper aroundboost::urls::resolve
:Which allows some simplification in
run
as well:Full Listing
Prints