我正在尝试使用cppnetlib或者boost asio库连接到URL并获取结果页面。已经成功使用http协议,甚至使用cppnetlib也可以使用https协议,但我需要提供一个需要密码的客户端证书。不幸的是,我必须使用旧版本v0.10的cppnetlib。
这个是否有可能?我想答案是创建自己的_io_service并为带有证书和密码的https请求进行自定义配置,然后将其提供给boost::network::http:client构造函数。以下代码在http中工作,并且对于无证书要求的https也适用。
这个是否有可能?我想答案是创建自己的_io_service并为带有证书和密码的https请求进行自定义配置,然后将其提供给boost::network::http:client构造函数。以下代码在http中工作,并且对于无证书要求的https也适用。
std::string url = "http://www.boost.org";
std::string certFile = "C:\\cert\\mycert.p12";
std::string password = "MyPassWord";
try {
http::client client;
http::client::request request(url);
http::client::response response = client->get(request);
std::string resultText = static_cast<std::string>(body(response));
std::cout << resultText << std::endl;
delete client;
}
catch (std::exception &e) {
std::cerr << "Caught something connecting " << e.what() << std::endl;
}