如何在POCO C ++库中正确使用OpenSSL [英] How to use OpenSSL in POCO C++ library correctly
问题描述
根据POCO助手中的规范:
According to the Specification in POCO assistant:
初始化NetSSL库以及基础的OpenSSL 库,方法是调用Poco :: Crypto :: OpenSSLInitializer :: initialize(). 在使用NetSSL库中的任何类之前,应先调用它. NetSSL将通过以下方式自动初始化: Poco :: Crypto :: OpenSSLInitializer实例或类似机制 创建Context或SSLManager实例时. 但是,建议调用initializeSSL() 无论如何在应用程序启动时.
Initialize the NetSSL library, as well as the underlying OpenSSL libraries, by calling Poco::Crypto::OpenSSLInitializer::initialize(). Should be called before using any class from the NetSSL library. The NetSSL will be initialized automatically, through Poco::Crypto::OpenSSLInitializer instances or similar mechanisms when creating Context or SSLManager instances. However, it is recommended to call initializeSSL() in any case at application startup.
当我想使用HTTPSClientSession
时,是否必须首先构造一个Application对象?
如何在客户端中使用它?任何人都可以告诉我吗?非常感谢!
When I want to use HTTPSClientSession
,do I have to construct an Application object first?
How can I use it in Client? Any guy can tell me ?Thank you very much!
推荐答案
让我们以Net/samples/httpget为例,让我们将httpget/复制为新的httpsget目录:
Let's take Net/samples/httpget as an example, let's copy httpget/ as a new httpsget directory:
- 打开Makefile,将"PocoNetSSL"添加到target_libs
- 将"HTTPClientSession"替换为"HTTPSClientSession"
- 您需要创建Poco :: Net :: Context以供SSL使用
- 替换"HTTPClientSession会话(uri.getHost(),uri.getPort());"有以下两行:
const Context::Ptr context = new Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
HTTPSClientSession session(uri.getHost(), uri.getPort(), context);
摘要:
- 将PocoNetSSL添加为lib_depends
- 将Poco :: Net :: Context与HTTPSClientSession一起使用
这篇关于如何在POCO C ++库中正确使用OpenSSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!