-
-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy patheasy_info.cpp
More file actions
51 lines (40 loc) · 1.48 KB
/
easy_info.cpp
File metadata and controls
51 lines (40 loc) · 1.48 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
51
#include "curlcpp/curl_easy.h"
#include "curlcpp/curl_ios.h"
#include "curlcpp/curl_exception.h"
using std::ostringstream;
using curl::curl_easy;
using curl::curl_easy_exception;
using curl::curlcpp_traceback;
using curl::curl_ios;
/**
* This example shows how to use the easy interface and obtain
* informations about the current session.
*/
int main(int argc, const char **argv) {
// Let's declare a stream
ostringstream stream;
// We are going to put the request's output in the previously declared stream
curl_ios<ostringstream> ios(stream);
// Declaration of an easy object
curl_easy easy(ios);
// Add some option to the curl_easy object.
easy.add<CURLOPT_URL>("http://www.google.it");
easy.add<CURLOPT_FOLLOWLOCATION>(1L);
try {
easy.perform();
// Retrieve information about curl current session.
auto x = easy.get_info<CURLINFO_CONTENT_TYPE>();
/**
* get_info returns a curl_easy_info object. With the get method we retrieve
* the std::pair object associated with it: the first item is the return code of the
* request. The second is the element requested by the specified libcurl macro.
*/
std::cout<<x.get()<<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;
}