Skip to content

Commit

Permalink
Simplify HTTP crawler example
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Jun 20, 2016
1 parent 1421045 commit d896822
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions examples/http_crawl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#include "http_stream.hpp"
#include "urls_large_data.hpp"

#include <beast/core/streambuf.hpp>
#include <beast/http.hpp>
#include <boost/asio.hpp>
#include <iostream>

Expand All @@ -31,9 +32,10 @@ int main(int, char const*[])
ip::tcp::resolver r(ios);
auto it = r.resolve(
ip::tcp::resolver::query{host, "http"});
stream<ip::tcp::socket> hs(ios);
connect(hs.lowest_layer(), it);
auto ep = hs.lowest_layer().remote_endpoint();
streambuf sb;
ip::tcp::socket sock(ios);
connect(sock, it);
auto ep = sock.remote_endpoint();
request_v1<empty_body> req;
req.method = "GET";
req.url = "/";
Expand All @@ -42,10 +44,10 @@ int main(int, char const*[])
std::string(":") + std::to_string(ep.port()));
req.headers.insert("User-Agent", "beast/http");
prepare(req);
hs.write(req);
response_v1<string_body> resp;
hs.read(resp);
std::cout << resp;
write(sock, req);
response_v1<string_body> res;
beast::http::read(sock, sb, res);
std::cout << res;
}
catch(boost::system::system_error const& ec)
{
Expand Down

0 comments on commit d896822

Please sign in to comment.