forked from boostorg/beast
* Don't include the test code in coverage reports * Add test code for missing coverage Other: * Improve the README.md * Fix warning in sha1_context * Tidy up the examples use of namespaces * Various fixes to documentation and javadocs
36 lines
1.1 KiB
C++
36 lines
1.1 KiB
C++
//
|
|
// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com)
|
|
//
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
//
|
|
|
|
#include <beast/http.hpp>
|
|
#include <boost/asio.hpp>
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
int main()
|
|
{
|
|
// Normal boost::asio setup
|
|
std::string const host = "boost.org";
|
|
boost::asio::io_service ios;
|
|
boost::asio::ip::tcp::resolver r(ios);
|
|
boost::asio::ip::tcp::socket sock(ios);
|
|
boost::asio::connect(sock,
|
|
r.resolve(boost::asio::ip::tcp::resolver::query{host, "http"}));
|
|
|
|
// Send HTTP request using beast
|
|
beast::http::request_v1<beast::http::empty_body> req({"GET", "/", 11});
|
|
req.headers.replace("Host", host + ":" + std::to_string(sock.remote_endpoint().port()));
|
|
req.headers.replace("User-Agent", "Beast");
|
|
beast::http::prepare(req);
|
|
beast::http::write(sock, req);
|
|
|
|
// Receive and print HTTP response using beast
|
|
beast::streambuf sb;
|
|
beast::http::response_v1<beast::http::streambuf_body> resp;
|
|
beast::http::read(sock, sb, resp);
|
|
std::cout << resp;
|
|
}
|