Question

I'm having a strange problem with poco. I can build it fine, and link it to a test application. However when I download a url, no matter what url I use it reports a HostNotFound exception. The file is accessible in incognito browsers everywhere and resolvable in dns.... I'm somewhat at a loss for troubleshooting this... any ideas?

// dns on the machine showing error nslookup s3.amazonaws.com Server: UnKnown Address: 192.168.0.1

Non-authoritative answer: Name: s3-1.amazonaws.com Address: 72.21.215.196 Aliases: 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>");

}
Était-ce utile?

La solution 2

rebuilt poco net library, still got the same error.

to avoid wasting time with something so simple, just switched to use CHttpConnection (which also saved about 20MB of library requirements).

perhaps experienced poco developers will come up with a better idea.

Autres conseils

Just had a similar problem. Note your host name is "http://s3.amazonaws.com".

The actual name of the host is "s3.amazonaws.com". The "http://" part specifies the protocol. The class HTTPClientSession is only to be used for the http protocol anyway.

In my case, stripping off the "http://" and just using the actual host name worked correctly: "s3.amazonaws.com":

HTTPClientSession session("s3.amazonaws.com");

(Well, in my case it was "http://ws.audioscrobbler.com", but that's beside the point). Probably too late to find out if this was really the answer to your problem, the error does look a bit different to mine, but hopefully it might help someone arriving here through search, as I did.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top