A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/tghosgor/libashttp below:

tghosgor/libashttp: A C++ async HTTP client library to use in asynchronous applications while communicating with REST services.

An asynchronous HTTP library using Boost.ASIO as the backend.

auto client = ClientHTTPS::create("www.google.com", ioService);

{
  auto request = client->get("/");

  {
    request->onHeader([](const ErrorCode& ec, const Header& header) {
      std::cout << "request onheader " << ec << std::endl;

      std::cout << std::endl << "Header received; ec: " << ec << std::endl;

      std::cout << header.field() << std::endl;
    }).onBodyChunk([](const ErrorCode& ec, std::istream& is, std::size_t chunkSize) {
      std::cout << "request onbodychunk chunksize: " << chunkSize << ", ec: " << ec << std::endl;

      if (!ec) {
        std::cout << std::endl << "Body chunk received; ec: " << ec << std::endl;

        std::copy_n(std::istreambuf_iterator<char>{is}, chunkSize, std::ostreambuf_iterator<char>{std::cout});

        std::cout << std::endl;

        if (chunkSize == 0)// this is the last chunk
          std::cout << "all chunks received" << std::endl;
      }
    }).onTimeout([]() {
      std::cout << "timeout" << ec << std::endl;
    }).onComplete([client, request](const ErrorCode& ec) {
      std::cout << "oncomplete" << ec << std::endl;

      ioService.stop();
    });

    client->schedule(request);
  }
}

More through examples can be found in the repository.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4