Boost.Asio-Based Http Client Library (Like Libcurl)

Boost.ASIO-based HTTP client library (like libcurl)

The other day somebody recommended this on another thread:

http://cpp-netlib.github.com/

I think this is as high-level as you will find, but I'm not sure if it's mature enough yet (I would say it probably is since they've proposed it for Boost inclusion).

Sending http GET request using boost::asio, similar to cURL

boost::asio is not an application level library. So you can open a connection with it, do an SSL handshake and so on. But you cannot construct HTTP requests via boost::asio since it's designed to just send/receive data.

But, you can try to experiment with this asio HTTP client example. Probably this can be a good thing to start with.

Boost ASIO HTTP client POST

You're missing a carriage return and line feed on this line:

request_stream << "Content-Type: application/x-www-form-urlencoded";

beast : http bad request

You are doing a plain HTTP request to a HTTPS service. There is nothing wrong per se with your code, and you can reproduce exactly the same answer using e.g. curl:

$ curl http://api.binance.com:443/api/v3/depth

You may take a look at some of the beast examples using SSL. As far as I remember, beast lets you exchange the underlying stream from a plain TCP socket to a SSL socket.

Edit
For the api key configuration, you must elaborate more exactly what is needed.

Also remember, that boost beast is a very generic and low level library. There are only the most basic examples in the documentation, because the library is meant for library developers primarly. While beast is imho a brilliant library, there might be other web client libraries, that are easier to use if you only need to make simple web requests.

C++ Send data in body with Boost.asio and Beast library

To send data with your request you'll need to fill the body and specify the content type.

beast::http::request<beast::http::string_body> req;
req.method(beast::http::verb::post);
req.target("/");

If you want to send "key=value" as a "x-www-form-urlencoded" pair:

req.set(beast::http::field::content_type, "application/x-www-form-urlencoded");
req.body() = "name=foo";

Or raw data:

req.set(beast::http::field::content_type, "text/plain");
req.body() = "Some raw data";

What C++ libraries can I use to download HTTP web-page, other than libcurl?

Poco C++ has a HTTPClient class that is fairly easy to use. Here is their Networking tutorial. Poco C++ is also cross platform.

Here are some boost like recommendations from SO.

EDIT : If you haven't looked at Qt, they have a QNetworkRequest class. Seems a bit lower level than the Poco client, but might suit your needs. Here is an example using it.

C++ high level network lib to make HTTPS requests

I'd go with libcurl any day. It is the most complete library in respect to protocols, ported to numerous platforms, and you really only pay for what you use. Of course you'll also be needing OpenSSL for secure protocols like HTTPS.

On the other hand, if you already have bloated your application with Qt, you might be better served using the QSSLSocket to retrieve the data and QScriptEngine to parse the JSON.



Related Topics



Leave a reply



Submit