| 24 | */ |
| 25 | |
| 26 | int main() { |
| 27 | // Let's declare a stream |
| 28 | ostringstream stream; |
| 29 | // We are going to put the request's output in the previously declared stream |
| 30 | curl_ios<ostringstream> ios(stream); |
| 31 | |
| 32 | // Easy object to handle the connection, url and verbosity level. |
| 33 | curl_easy easy(ios); |
| 34 | easy.add<CURLOPT_URL>("http://example.com"); |
| 35 | |
| 36 | // Let's create a cookie which expires at Mon, 27-03-2016 20:30:30 GMT |
| 37 | cookie ck; |
| 38 | cookie_date date(curl::weekdays::MONDAY,27,curl::months::MARCH,2016); |
| 39 | cookie_time time(20,30,30); |
| 40 | cookie_datetime datetime(time,date); |
| 41 | |
| 42 | ck.set_name("nomecookie"); |
| 43 | ck.set_value("valorecookie"); |
| 44 | ck.set_path("/"); |
| 45 | ck.set_domain(".example.com"); |
| 46 | ck.set_datetime(datetime); |
| 47 | |
| 48 | // Create a cookie object and add the previously created cookie. |
| 49 | curl_cookie cookie_object(easy); |
| 50 | cookie_object.set(ck); |
| 51 | |
| 52 | try { |
| 53 | easy.perform(); |
| 54 | |
| 55 | // Retrieve all the cookies for the example.com (as a vector) |
| 56 | curlcpp_cookies cookies = cookie_object.get(); |
| 57 | // Delete all the memory helded cookies. |
| 58 | cookie_object.erase(); |
| 59 | |
| 60 | // Print them all! |
| 61 | for (const auto& cook : cookies) { |
| 62 | std::cout<<cook<<std::endl; |
| 63 | } |
| 64 | } catch (curl_easy_exception &error) { |
| 65 | // If you want to print the last error. |
| 66 | std::cerr<<error.what()<<std::endl; |
| 67 | |
| 68 | // If you want to print the entire error stack you can do. |
| 69 | error.print_traceback(); |
| 70 | } |
| 71 | return 0; |
| 72 | } |
nothing calls this directly
no test coverage detected