* This example shows how to split the received headers and body content * into two different streams */
| 11 | * into two different streams |
| 12 | */ |
| 13 | int 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 | } |
nothing calls this directly
no test coverage detected