client.cc 926 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // client.cc
  3. //
  4. // Copyright (c) 2019 Yuji Hirose. All rights reserved.
  5. // MIT License
  6. //
  7. #include <httplib.h>
  8. #include <iostream>
  9. #define CA_CERT_FILE "./ca-bundle.crt"
  10. using namespace std;
  11. int main(void) {
  12. #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
  13. httplib::SSLClient cli("localhost", 8080);
  14. // httplib::SSLClient cli("google.com");
  15. // httplib::SSLClient cli("www.youtube.com");
  16. cli.set_ca_cert_path(CA_CERT_FILE);
  17. cli.enable_server_certificate_verification(true);
  18. #else
  19. httplib::Client cli("localhost", 8080);
  20. #endif
  21. auto res = cli.Get("/hi");
  22. if (res) {
  23. cout << res->status << endl;
  24. cout << res->get_header_value("Content-Type") << endl;
  25. cout << res->body << endl;
  26. } else {
  27. #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
  28. auto result = cli.get_openssl_verify_result();
  29. if (result) {
  30. cout << "verify error: " << X509_verify_cert_error_string(result) << endl;
  31. }
  32. #endif
  33. }
  34. return 0;
  35. }