mirror of
https://github.com/boostorg/beast.git
synced 2026-01-27 01:32:18 +01:00
fix #397 method enum class is added to represent all known request methods. Functions are provided to convert from strings to and from the method enumeration. The fields container is modified to also work with the enum.
42 lines
1.3 KiB
C++
42 lines
1.3 KiB
C++
//
|
|
// Copyright (c) 2013-2017 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/core.hpp>
|
|
#include <beast/http.hpp>
|
|
#include <boost/asio.hpp>
|
|
#include <boost/lexical_cast.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<beast::http::string_body> req;
|
|
req.method(beast::http::verb::get);
|
|
req.target("/");
|
|
req.version = 11;
|
|
req.fields.replace("Host", host + ":" +
|
|
boost::lexical_cast<std::string>(sock.remote_endpoint().port()));
|
|
req.fields.replace("User-Agent", "Beast");
|
|
beast::http::prepare(req);
|
|
beast::http::write(sock, req);
|
|
|
|
// Receive and print HTTP response using beast
|
|
beast::flat_buffer b;
|
|
beast::http::response<beast::http::dynamic_body> res;
|
|
beast::http::read(sock, b, res);
|
|
std::cout << res;
|
|
}
|