tags:

views:

92

answers:

5

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.

+3  A: 

Check out libCURL it will do this for you.

Vlad
+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
A: 

There is a free HTTP library included with Ultimate TCP/IP.

Rob
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