example23.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * \file
  3. * Setting request options using iterators to custom container of curlpp options.
  4. *
  5. */
  6. #include <vector>
  7. #include <curlpp/cURLpp.hpp>
  8. #include <curlpp/Easy.hpp>
  9. #include <curlpp/Options.hpp>
  10. using namespace curlpp::options;
  11. int main(int, char **)
  12. {
  13. try
  14. {
  15. // That's all that is needed to do cleanup of used resources (RAII style).
  16. curlpp::Cleanup myCleanup;
  17. // Our request to be sent.
  18. curlpp::Easy myRequest;
  19. // Container of our choice with pointers to curlpp options.
  20. std::vector<curlpp::OptionBase *> options;
  21. options.push_back(new Url("http://example.com"));
  22. options.push_back(new Port(80));
  23. // Set all options in range to the Easy handle.
  24. myRequest.setOpt(options.begin(), options.end());
  25. // Send request and get a result.
  26. // By default the result goes to standard output.
  27. myRequest.perform();
  28. }
  29. catch(curlpp::RuntimeError & e)
  30. {
  31. std::cout << e.what() << std::endl;
  32. }
  33. catch(curlpp::LogicError & e)
  34. {
  35. std::cout << e.what() << std::endl;
  36. }
  37. return 0;
  38. }