Boost.ASIO-based HTTP client library (like libcurl) [closed]

匿名 (未验证) 提交于 2019-12-03 02:45:02

问题:

I am looking for a modern C++ HTTP library because libcurl's shortcomings are difficult to work around by C++ wrappers. Solutions based on Boost.ASIO, which has become the de-facto C++ TCP library, are preferred.

回答1:

The other day somebody recommended this on another thread:

http://cpp-netlib.github.com/

I think this is as high-level as you will find, but I'm not sure if it's mature enough yet (I would say it probably is since they've proposed it for Boost inclusion).



回答2:

Better late than never, here's a new answer to an old question. There's this new open source library called Boost.Beast which offers both HTTP and WebSocket functionality using Boost.Asio. It emulates the familiar Asio interfaces as closely as possible, and its got plenty of documentation. It builds on clang, gcc, and Visual Studio using either bjam or CMake - your choice! Note, I am also the author of the library.

https://github.com/boostorg/beast/

Here's a complete example program that retrieves a web page:

#include  #include  #include  #include  #include  #include  #include  #include   using tcp = boost::asio::ip::tcp;       // from  namespace http = boost::beast::http;    // from   // Performs an HTTP GET and prints the response int main(int argc, char** argv) {     try     {         // Check command line arguments.         if(argc != 4 && argc != 5)         {             std::cerr   []\n"  req{http::verb::get, target, version};         req.set(http::field::host, host);         req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);          // Send the HTTP request to the remote host         http::write(socket, req);          // This buffer is used for reading and must be persisted         boost::beast::flat_buffer buffer;          // Declare a container to hold the response         http::response<:dynamic_body> res;          // Receive the HTTP response         http::read(socket, buffer, res);          // Write the message to standard out         std::cout 


回答3:

asio author implement:



回答4:

You should also check out the Pion Network Library:

http://pion.org/projects/pion-network-library



回答5:

Boost.Http - a new player here: https://github.com/BoostGSoC14/boost.http, docs - http://boostgsoc14.github.io/boost.http/



回答6:

There's this project trying to "Boostify" libcurl: https://github.com/breese/trial.url

I'll use this as a reference to design Boost.Http client API. However, I plan to focus on high-level abstractions and try to collaborate as much as possible with Beast.HTTP author.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!