MCPcopy Create free account
hub / github.com/JosephP91/curlcpp / main

Function main

test/recv_header.cpp:13–50  ·  view source on GitHub ↗

* This example shows how to split the received headers and body content * into two different streams */

Source from the content-addressed store, hash-verified

11 * into two different streams
12 */
13int main() {
14 // Create two different ostringstream objects
15 ostringstream body_var;
16 ostringstream header_var;
17
18 // The "body" stream will put the body content into "body_var"
19 curl_ios<ostringstream> body(body_var);
20 // The "header" stream will put the headers into "header_var"
21 curl_ios<ostringstream> header(header_var);
22
23 // Easy object to handle the connection.
24 curl_easy easy;
25
26 // We will use the default write function
27 easy.add<CURLOPT_WRITEFUNCTION>(header.get_function());
28
29 // Specify the stream for headers content.
30 easy.add<CURLOPT_HEADERDATA>(header.get_stream());
31
32 // Specify the stream for body content.
33 easy.add<CURLOPT_WRITEDATA>(body.get_stream());
34 easy.add<CURLOPT_URL>("http://www.example.com");
35
36 try {
37 easy.perform();
38
39 // Let's print ONLY the headers.
40 std::cout<<header_var.str()<<std::endl;
41
42 } catch (curl_easy_exception &error) {
43 // If you want to print the last error.
44 std::cerr<<error.what()<<std::endl;
45
46 // If you want to print the entire error stack you can do
47 error.print_traceback();
48 }
49 return 0;
50}

Callers

nothing calls this directly

Calls 4

print_tracebackMethod · 0.80
get_functionMethod · 0.45
get_streamMethod · 0.45
performMethod · 0.45

Tested by

no test coverage detected