G
G
German2018-07-07 00:09:14
Boost
German, 2018-07-07 00:09:14

How to return only text when reading response from boost beast site?

#include "stdafx.h"
#include <boost/beast.hpp>
#include <boost/asio/connect.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <Windows.h>

namespace http = boost::beast::http;

int main()
{
  const std::string host = "ahri9fox.online";
  //const std::string target = "/chat/chat.php?request=check";
  const std::string target = "/chat/messages.txt";
  boost::asio::io_context ioc;
  boost::asio::ip::tcp::resolver resolver(ioc);
  boost::asio::ip::tcp::socket socket(ioc);
  boost::asio::connect(socket, resolver.resolve(host, "80"));
  http::request<http::string_body> req(http::verb::get, target, 11);
  req.set(http::field::host, host);
  req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);
  http::write(socket, req);
  {
    boost::beast::flat_buffer buffer;
    http::response<http::dynamic_body> res;
    http::read(socket, buffer, res);
    std::cout << res << std::endl;
  }
  socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both);
  system("pause");
  return 0;
}

The text in the document
Test1
Test2
How to return exactly it? And not this one.
5b3fda1b9804a216046725.png
I would also like to know how to convert the response to string.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wexter, 2018-07-07
@Wexter

google://protocol+http
You need either an HTTP client or a parser. If there is no need to parse headings, cut the text to two line breaks

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question