Simple proxy using C++/boost::asio/libcurl - can't download images

萝らか妹 提交于 2019-12-04 19:51:14
Lightness Races with Monica

Just like on Convert server response (std::string) into a png file, you're using std::string wrongly.

For example, the following code:

curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); 

assumes that &response is a pointer to a character array or buffer. However, it's not: it's a pointer to an std::string, a complex object with implementation-defined internals.

You should use its well-defined API instead, referring to your favourite from this list of recommended reading material.


You will find that working with this C-style cURL API and std::string is not entirely intuitive. Why not use the C++ binding, cURLpp?

In answer to the follow up question: I would use the overload of async_write which takes a streambuf:

boost::async_write( socket_, os.rdbuf(), boost::bind(&session::handle_write, this, boost::asio::placeholders::error ) )
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!