Hi, I'm looking for a basic tutorial for connecting to a domain and downloading the index file . Anyone that can link me a good example or anything.
A:
Johann Gerell
2010-05-05 18:30:46
+1
A:
The simplest solution is using URLDownloadToFile.
However, you can use all these APIs together:
I'm pretty sure there's still another simple API for that, but I don't remember right now.
jweyrich
2010-05-05 18:49:01
A:
I use Poco for that. as a side benefir it's also portable (works on Linux and other OSs as well).
void openHttpURL(string host, int port, string path)
{
try
{
HTTPClientSession session(host, port);
// session.setTimeout(Timespan(connectionTimeout, 0));
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
session.sendRequest(req);
HTTPResponse res;
int code = res.getStatus();
if (code != res.HTTP_OK)
{
stringstream s;
s << "HTTP Error " << code;
throw Poco::IOException(s.str());
}
std::istream& rs = session.receiveResponse(res);
int len = res.getContentLength();
// READ DATA FROM THE STREAM HERE
}
catch (Exception& exc)
{
stringstream s;
s << "Error connecting to http://" << host << ':' << port << "/" << path + " : " + exc.displayText();
throw Poco::IOException(s.str());
}
}
Omry
2010-05-06 07:25:53