错误 w/ C++ poco 和 HTTPSStreamFactory
我正在尝试构建一个 C++ 应用程序来访问 XML 资源。使用http,代码工作正常,从我从文档中可以看出,要让https工作,我需要做的就是确保安装ssl(是的,安装了开发版本),并将StreamFactory更改为HTTPSStreamFactory。
这是有效的代码:
Poco::Net::HTTPStreamFactory::registerFactory();
Poco::URI uri(argv[1]);
std::auto_ptr<std::istream> pStr(Poco::URIStreamOpener::defaultOpener().open(uri));
std::string str;
StreamCopier::copyToString(*pStr.get(), str);
这是失败的代码 Poco::Net::HTTPSStreamFactory::registerFactory(); Poco::URI uri(argv[1]);
std::auto_ptr<std::istream> pStr(Poco::URIStreamOpener::defaultOpener().open(uri));
std::string str;
StreamCopier::copyToString(*pStr.get(), str);
当我使用 HTTPSStreamFactory 发出请求时,这是我收到的错误消息:
NULL 指针:_pInstance [在文件中 “/home/chpick/poco-1.3.6p2/Util/include/Poco/Util/Application.h”, 第422行]
我已附上 Application.h
inline Application& Application::instance()
{
poco_check_ptr (_pInstance);
return *_pInstance;
}
任何帮助都会很棒。谢谢
I am trying to build a C++ app to access a XML resource. Using http the code works fine, from what I can tell from the docs, all I need to do to for the https to work is to make sure ssl is install (yes the dev edition is installed), and change the StreamFactory to HTTPSStreamFactory.
Here is the code that works :
Poco::Net::HTTPStreamFactory::registerFactory();
Poco::URI uri(argv[1]);
std::auto_ptr<std::istream> pStr(Poco::URIStreamOpener::defaultOpener().open(uri));
std::string str;
StreamCopier::copyToString(*pStr.get(), str);
Here is the code that fails
Poco::Net::HTTPSStreamFactory::registerFactory();
Poco::URI uri(argv[1]);
std::auto_ptr<std::istream> pStr(Poco::URIStreamOpener::defaultOpener().open(uri));
std::string str;
StreamCopier::copyToString(*pStr.get(), str);
When I make a request w/ HTTPSStreamFactory this is the error message I get :
NULL pointer: _pInstance [in file
"/home/chpick/poco-1.3.6p2/Util/include/Poco/Util/Application.h",
line 422]
I have attached the Application.h
inline Application& Application::instance()
{
poco_check_ptr (_pInstance);
return *_pInstance;
}
Any help would be great. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查文档中是否有类似于检查证书的内容。您会看到,SSL 通过服务器和客户端交换证书来工作,在我使用过的每个支持 SSL 的库中,开发人员必须创建一个函数或以其他方式验证服务器发送的证书;这通常意味着开发人员不检查就接受任何内容,因为大多数人并不真正关心这一点。您的程序可能会出现段错误,因为正在调用该代码,并且没有返回任何内容,因此正在取消引用 null 或类似的情况。
Check the documentation for something along the lines of check certificate. You see, SSL works by the server and client exchanging certificates, and in every library I've used that does SSL, the developer has to create a function or in some other way validate the certificate the server sent; which usually means the developer just accepts anything without checking because most people don't really care about that. You program might be seg-faulting because that code is being called, and nothing is being returned, so a null is being dereferenced, or something like that.
我最终以不同的方式解决了这个问题:这就是我所做的。
I ended up going about it a different way : Here is what I did.