我对 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>");
}