即使主机解析,poco httpclientsession 也会给主机未找到错误

fey*_*ard 1 visual-c++ poco-libraries

我对 poco 有一个奇怪的问题。我可以很好地构建它,并将其链接到测试应用程序。但是,当我下载一个 url 时,无论我使用什么 url,它都会报告 HostNotFound 异常。该文件可以在任何地方的隐身浏览器中访问,并且可以在 dns 中解析......我对解决这个问题感到有些茫然......有什么想法吗?

// 机器上的 dns 显示错误 nslookup s3.amazonaws.com 服务器:未知地址:192.168.0.1

非权威回答:名称:s3-1.amazonaws.com 地址:72.21.215.196 别名:s3.amazonaws.com s3.a-geo.amazonaws.com

    // calling helper
CString host("http://s3.amazonaws.com");
CString path("/mybucket.mycompany.com/myfile.txt");
CString errmsg;
CString data = GetURL(host,path,errmsg);

    // poco helper code
 CString  GetURL(CString host, CString path_query, CString &debmsg)
{

    debmsg = CString("");
    try 
    {
        // convert request
        std::string tmphost((LPCTSTR)host);
        std::string tmppath((LPCTSTR)path_query);
        // creation session and request
        HTTPClientSession session(tmphost,80);
        // disable proxy
        session.setProxyHost("");
        HTTPRequest req(HTTPRequest::HTTP_GET,tmppath,HTTPMessage::HTTP_1_1);

        // send request
        session.sendRequest(req);
        // get response
        HTTPResponse res;

        std::istream * response = &session.receiveResponse(res);

        // convert it back to mfc string
        streambuf *pbuf = response->rdbuf();
        std::ostringstream ss;
        ss << pbuf;

        CString data(ss.str().c_str());

        return data;
    }
    catch (Poco::Exception& ex)
    {
        CString err(ex.displayText().c_str());
        debmsg.Format("error getting url: %s%s err: %s",host,path_query,err);
    }

    return CString("<error>");

}
Run Code Online (Sandbox Code Playgroud)

BoB*_*ish 5

刚刚遇到了类似的问题。请注意,您的主机名是"http://s3.amazonaws.com".

主机的实际名称是"s3.amazonaws.com". 该"http://"部分指定协议HTTPClientSession无论如何,该类仅用于 http 协议。

就我而言,剥离"http://"并仅使用实际主机名可以正常工作"s3.amazonaws.com"::

HTTPClientSession session("s3.amazonaws.com");
Run Code Online (Sandbox Code Playgroud)

(好吧,就我而言,它是"http://ws.audioscrobbler.com",但这无关紧要)。找出这是否真的是您问题的答案可能为时已晚,该错误看起来与我的有点不同,但希望它可以帮助像我一样通过搜索到达这里的人。