Skip to content

SSL Example seems not working #281

@ghost

Description

Hi,
I am trying to execute your client.cc example as follows;

//
//  client.cc
//
//  Copyright (c) 2019 Yuji Hirose. All rights reserved.
//  MIT License
//
#define CPPHTTPLIB_OPENSSL_SUPPORT 1
#include <httplib/httplib.h>
#include <iostream>

#define CA_CERT_FILE "./ca-bundle.crt"

using namespace std;

int main(void) {
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
  //httplib::SSLClient cli("localhost", 8080);
  httplib::SSLClient cli("google.com");
  // httplib::SSLClient cli("www.youtube.com");
  //cli.set_ca_cert_path(CA_CERT_FILE);
  //cli.enable_server_certificate_verification(true);
#else
  httplib::Client cli("localhost", 8080);
#endif

  auto res = cli.Get("/hi");
  if (res) {
    cout << res->status << endl;
    cout << res->get_header_value("Content-Type") << endl;
    cout << res->body << endl;
  } else {
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
    auto result = cli.get_openssl_verify_result();
    if (result) {
      cout << "verify error: " << X509_verify_cert_error_string(result) << endl;
    }
#endif
  }

  return 0;
}

But if fails on line 3364

  req.content_provider(offset, end_offset - offset,
                             [&](const char *d, size_t l) {
                               auto written_length = strm.write(d, l);
                               offset += written_length;
                             });

cmake version 3.10.2
Ubuntu 18.04
gcc version 7.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions