File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include " curl_easy.h"
2
+ #include " curl_form.h"
3
+ #include " curl_header.h"
4
+
5
+ using curl::curl_header;
6
+ using curl::curl_easy;
7
+ using curl::curl_easy_exception;
8
+ using curl::curlcpp_traceback;
9
+
10
+ int main () {
11
+ // Let's create an object which will contain a list of headers.
12
+ curl_header header;
13
+ // Easy object to handle the connection.
14
+ curl_easy easy;
15
+
16
+ // Add custom headers.
17
+ std::string jsonInfo = " {\" username\" :\" abc\" ,\" password\" :\" abc\" }" ;
18
+ header.add (jsonInfo);
19
+ header.add (" Content-type: application/json" );
20
+
21
+ // Add the headers to the easy object.
22
+ easy.add <CURLOPT_HTTPHEADER>(header.get ());
23
+ // Your URL.
24
+ easy.add <CURLOPT_URL>(" http://yoururl" );
25
+ // Custom request.
26
+ easy.add <CURLOPT_CUSTOMREQUEST>(" PUT" );
27
+ // You can choose between 1L and 0L (enable verbose video log or disable)
28
+ easy.add <CURLOPT_VERBOSE>(0L );
29
+
30
+ try {
31
+ // Request execution
32
+ easy.perform ();
33
+ } catch (curl_easy_exception error) {
34
+ // If you want to get the entire error stack we can do:
35
+ curlcpp_traceback errors = error.get_traceback ();
36
+ // Otherwise we could print the stack like this:
37
+ error.print_traceback ();
38
+ }
39
+ return 0 ;
40
+ }
You can’t perform that action at this time.
0 commit comments