错误 w/ C++ poco 和 HTTPSStreamFactory

发布于 2024-09-09 07:52:16 字数 1065 浏览 7 评论 0原文

我正在尝试构建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百善笑为先 2024-09-16 07:52:16

检查文档中是否有类似于检查证书的内容。您会看到,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.

被你宠の有点坏 2024-09-16 07:52:16

我最终以不同的方式解决了这个问题:这就是我所做的。

    const Poco::URI uri(xmlParams.restURI);
    std::string path(argv[1]);
    const Poco::Net::Context::Ptr context = new Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
    Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort(), context );
    Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, argv[1] );
    req.setKeepAlive(false);

  std::string strToSend = "/";
    session.sendRequest(req) << strToSend;
    Poco::Net::HTTPResponse res;
    std::istream& rs = session.receiveResponse(res);    // typedef std::istream XMLCharInputStream;

    std::string str;    
    StreamCopier::copyToString(rs, str);

    std::istringstream istr(str);
    InputSource source(istr);
    parser.parse(&source);

I ended up going about it a different way : Here is what I did.

    const Poco::URI uri(xmlParams.restURI);
    std::string path(argv[1]);
    const Poco::Net::Context::Ptr context = new Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
    Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort(), context );
    Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, argv[1] );
    req.setKeepAlive(false);

  std::string strToSend = "/";
    session.sendRequest(req) << strToSend;
    Poco::Net::HTTPResponse res;
    std::istream& rs = session.receiveResponse(res);    // typedef std::istream XMLCharInputStream;

    std::string str;    
    StreamCopier::copyToString(rs, str);

    std::istringstream istr(str);
    InputSource source(istr);
    parser.parse(&source);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文