Note that there are some explanatory texts on larger screens.

plurals
  1. POConcat boost::asio::read() response
    primarykey
    data
    text
    <p>Juste a short question... I use sync_client.cpp, an exemple given by boost.asio, for try this librairy. Code :</p> <pre><code>#include &lt;iostream&gt; #include &lt;istream&gt; #include &lt;ostream&gt; #include &lt;string&gt; #include &lt;string.h&gt; #include &lt;boost/asio.hpp&gt; using boost::asio::ip::tcp; int main(int argc, char* argv[]) { try { boost::asio::io_service io_service; // Get a list of endpoints corresponding to the server name. tcp::resolver resolver(io_service); tcp::resolver::query query(argv[1], "http"); tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); // Try each endpoint until we successfully establish a connection. tcp::socket socket(io_service); boost::asio::connect(socket, endpoint_iterator); // Form the request. We specify the "Connection: close" header so that the // server will close the socket after transmitting the response. This will // allow us to treat all data up until the EOF as the content. boost::asio::streambuf request; std::ostream request_stream(&amp;request); request_stream &lt;&lt; "GET " &lt;&lt; argv[2] &lt;&lt; " HTTP/1.0\r\n"; request_stream &lt;&lt; "Host: " &lt;&lt; argv[1] &lt;&lt; "\r\n"; request_stream &lt;&lt; "Accept: */*\r\n"; request_stream &lt;&lt; "Connection: close\r\n\r\n"; // Send the request. boost::asio::write(socket, request); // Read the response status line. The response streambuf will automatically // grow to accommodate the entire line. The growth may be limited by passing // a maximum size to the streambuf constructor. boost::asio::streambuf response; boost::asio::read_until(socket, response, "\r\n"); // Check that response is OK. std::istream response_stream(&amp;response); std::string http_version; response_stream &gt;&gt; http_version; unsigned int status_code; response_stream &gt;&gt; status_code; std::string status_message; std::getline(response_stream, status_message); if (!response_stream || http_version.substr(0, 5) != "HTTP/") { std::cout &lt;&lt; "Invalid response\n"; return 1; } if (status_code != 200) { std::cout &lt;&lt; "Response returned with status code " &lt;&lt; status_code &lt;&lt; "\n"; return 1; } // Read the response headers, which are terminated by a blank line. boost::asio::read_until(socket, response, "\r\n\r\n"); // Process the response headers. std::string header; while (std::getline(response_stream, header) &amp;&amp; header != "\r") std::cout &lt;&lt; header &lt;&lt; "\n"; std::cout &lt;&lt; "\n"; // Write whatever content we already have to output. if (response.size() &gt; 0) std::cout &lt;&lt; &amp;response; // Read until EOF, writing data to output as we go. boost::system::error_code error; while (boost::asio::read(socket, response, boost::asio::transfer_at_least(1), error)) std::cout &lt;&lt; &amp;response; if (error != boost::asio::error::eof) throw boost::system::system_error(error); } catch (std::exception&amp; e) { std::cout &lt;&lt; "Exception: " &lt;&lt; e.what() &lt;&lt; "\n"; } return 0; } </code></pre> <p>But this code, show the result in the prump. I want to put the response in a different var for work on it after.</p> <p>I'm newbie and sorry for my english. Thank a lot !</p> <p><strong>EDIT :</strong></p> <p>It's good i have found a solution.</p> <pre><code>std::stringstream s; while (boost::asio::read(socket, response, boost::asio::transfer_at_least(1), error)) s &lt;&lt; &amp;response; const std::string htmlContent = s.str(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload