Download a URL in C++

I wouldn't go to Qt just for the networking stuff, since it's really not all that spectacular; there are a lot of missing pieces. I'd only switch if you need the GUI stuff, for which it is top notch.

libCURL is pretty simple to use and more robust than the Qt stuff.


Not a direct answer, but you might like to consider libCURL, which is almost exactly what you describe.

There are sample applications here, and in particular this demonstrates how simple usage can be.


You can use URLDownloadToFile.

#include <Urlmon.h>
    HANDLE hr;
    hr=URLDownloadToFile(NULL, L"http://www.example.com/myfile.html",L"mylocalfile.html",BINDF_GETNEWESTVERSION,NULL);

According to MSDN, BINDF_GETNEWESTVERSION - is a "Value that indicates that the bind operation retrieves the newest version of the data or object available. In URL monikers, this flag maps to the WinInet flag, INTERNET_FLAG_RELOAD, which forces a download of the requested resource".

Tags:

C++

Sockets