Reqres APIに対していくつかの機能をテストするために、C++ で単純な HTTPS クライアントをセットアップしようとしています。
メインの C++ ネットワーク ライブラリとしてcpp-netlibを使用しています。ドキュメントで提供されている例に基づいて、いくつかの GET クエリを実行するコードをいくつか書きました。
#ifndef BOOST_NETWORK_ENABLE_HTTPS
# define BOOST_NETWORK_ENABLE_HTTPS
#endif // !BOOST_NETWORK_ENABLE_HTTPS
#include <boost/network/protocol/http/client.hpp>
#include <iostream>
using namespace boost::network::http;
int main() {
client::options options;
options.follow_redirects(true)
.cache_resolved(true)
.timeout(10);
client client_(options);
client::request request_("https://reqres.in/api/users");
client::response response_ = client_.get(request_);
std::cout << body(response_) << std::endl;
return 0;
}
コードを実行すると、次の例外が発生します。
libc++abi.dylib: terminating with uncaught exception of type boost::exception_detail::clone_impl<boost::system::system_error>: sslv3 alert handshake failure
問題は OpenSSL 構成に関連していると思います。CSR と KEY を生成して、ハンドシェイクで使用する証明書を生成しようとしました。
openssl req -new -newkey rsa:4096 -nodes -keyout mohabouje.key -out mohabouje.csr
そしてPEM:
openssl x509 -req -sha256 -days 365 -in mohabouje.csr -signkey mohabouje.key -out mohabouje.pem
クライアント オプションでこれらのファイルを使用するように、コードを変更しました。
client::options options;
options.follow_redirects(true)
.cache_resolved(true)
.openssl_certificate_file("/opt/ssl/mohabouje.csr")
.openssl_private_key_file("/opt/ssl/mohabouje.key")
.timeout(10);
しかし今、私はこの例外を受けています:
libc++abi.dylib: terminating with uncaught exception of type boost::wrapexcept<boost::system::system_error>: use_certificate_file: no start line
代わりに、私はこれを試しました:
client::options options;
options.follow_redirects(true)
.cache_resolved(true)
.openssl_certificate_file("/opt/ssl/mohabouje.pem")
.openssl_private_key_file("/opt/ssl/mohabouje.key")
.timeout(10);
しかし、私は同じ例外を受け取ります:
libc++abi.dylib: terminating with uncaught exception of type boost::exception_detail::clone_impl<boost::system::system_error>: sslv3 alert handshake failure
私は何を間違っていますか?このパブリック API に対する単純なクエリの実際の例を提供できる人はいますか?