Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Here is an example of a c++ application that can make requests and receive responses. Then see for yourself what to do with these answers.
Just like in any other programming language - send an HTTP request to the site, receive and parse the response. There are many libraries for this, with which this can be done quite easily.
You can do the same without third-party libraries, but it will be much more difficult and you will have to figure everything out yourself.
In the C++ language itself, of course, there are no built-in means for this.
#include <iostream>
#include <boost/beast.hpp>
namespace asio = boost::asio;
namespace beast = boost::beast;
namespace http = boost::beast::http;
int main(int argc, char** argv)
{
asio::io_context io;
asio::ip::tcp::socket socket(io);
asio::ip::tcp::resolver resolver(io);
asio::connect(socket, resolver.resolve("scooterlabs.com", "http"));
http::request<http::empty_body> request(http::verb::get, "/echo", 11);
request.set(http::field::host, "scooterlabs.com");
request.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);
http::write(socket, request);
beast::flat_buffer buffer;
http::response<http::string_body> response;
http::read(socket, buffer, response);
std::cout << response.body() << std::endl;
socket.shutdown(socket.shutdown_both);
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question