-
-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathrecv_header.cpp
More file actions
50 lines (39 loc) · 1.4 KB
/
recv_header.cpp
File metadata and controls
50 lines (39 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "curlcpp/curl_easy.h"
#include "curlcpp/curl_form.h"
using curl::curl_easy;
using curl::curl_ios;
using curl::curl_easy_exception;
using std::ostringstream;
/**
* This example shows how to split the received headers and body content
* into two different streams
*/
int main() {
// Create two different ostringstream objects
ostringstream body_var;
ostringstream header_var;
// The "body" stream will put the body content into "body_var"
curl_ios<ostringstream> body(body_var);
// The "header" stream will put the headers into "header_var"
curl_ios<ostringstream> header(header_var);
// Easy object to handle the connection.
curl_easy easy;
// We will use the default write function
easy.add<CURLOPT_WRITEFUNCTION>(header.get_function());
// Specify the stream for headers content.
easy.add<CURLOPT_HEADERDATA>(header.get_stream());
// Specify the stream for body content.
easy.add<CURLOPT_WRITEDATA>(body.get_stream());
easy.add<CURLOPT_URL>("http://www.example.com");
try {
easy.perform();
// Let's print ONLY the headers.
std::cout<<header_var.str()<<std::endl;
} catch (curl_easy_exception &error) {
// If you want to print the last error.
std::cerr<<error.what()<<std::endl;
// If you want to print the entire error stack you can do
error.print_traceback();
}
return 0;
}