views:

369

answers:

4

There are a lot of examples how to make HTTP request to a server and get reply via boost.asio library. However, I couldn't find a good example of simple interface and wondering, if I need to implement it myself.

For instance, if I need to get content of http://www.foo.bar/path/to/default.html, is there any way to get a content without validating URL, making HTTP request and parsing server answer?

Basically, I am looking for something like this:

std::string str = boost::asio::get_content("http://www.foo.bar/path/to/default.html");
std::cout << str;

#
<HTML>
  <BODY>
    Simple HTML page!
  </BODY>
</HTML>

There are couple of things that I would like to avoid using boost.asio.

  • Avoid parsing and validating URL.
  • Manually creating HTTP request.
  • Cutting HTTP response from HTML page content.
+1  A: 

You'll need to implement these functions yourself. Boost.Asio is a socket library primarily, that can be used to implement various protocols. But there's no built-in convenience functions just for some specific protocol like HTTP or SMTP. (Well, actually there's built in DNS resolution, but that's about it.)

However, the Boost.Asio source code comes with pre-made examples of an HTTP client/server, so you can easily start with that.

Charles Salvia
+1  A: 

boost.asio is powerful and sophisticated, but probably overkill for this.

Have you looked at libcurl?

ravenspoint
A: 

boost.asio doesn't provide such functionality. But I believe there are a number of libraries that do. See POCO libraries for example.

begray
A: 

From the person who wrote boost.asio

http://think-async.com/Urdl/doc/html/urdl/getting_started/integrating_with_boost_asio.html

boost::urdl is a library for reading urls into strings easily.

pwned