* This example shows how to perform a custom request. */
| 10 | * This example shows how to perform a custom request. |
| 11 | */ |
| 12 | int 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 | } |
nothing calls this directly
no test coverage detected