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

Function main

test/custom_request.cpp:12–43  ·  view source on GitHub ↗

* This example shows how to perform a custom request. */

Source from the content-addressed store, hash-verified

10 * This example shows how to perform a custom request.
11 */
12int main() {
13 // Let's create an object which will contain a list of headers.
14 curl::curl_header header;
15 // Easy object to handle the connection.
16 curl_easy easy;
17
18 // Add custom headers.
19 std::string jsonInfo = R"({"username":"abc","password":"abc"})";
20 header.add(jsonInfo);
21 header.add("Content-type: application/json");
22
23 // Add the headers to the easy object.
24 easy.add<CURLOPT_HTTPHEADER>(header.get());
25 // Your URL.
26 easy.add<CURLOPT_URL>("http://example.com");
27 // Custom request.
28 easy.add<CURLOPT_CUSTOMREQUEST>("PUT");
29 // You can choose between 1L and 0L (enable verbose video log or disable)
30 easy.add<CURLOPT_VERBOSE>(0L);
31
32 try {
33 // Request execution
34 easy.perform();
35 } catch (curl_easy_exception &error) {
36 // If you want to print the last error.
37 std::cerr<<error.what()<<std::endl;
38
39 // If you want to print the entire error stack you can do
40 error.print_traceback();
41 }
42 return 0;
43}

Callers

nothing calls this directly

Calls 4

print_tracebackMethod · 0.80
addMethod · 0.45
getMethod · 0.45
performMethod · 0.45

Tested by

no test coverage detected