tags:

views:

928

answers:

4

I want to be able to download a URL in C++. Something as simple as:

std::string s;
s=download("http://www.example.com/myfile.html");

Ideally, this would include URLs like:

I was using asio in Boost, but it didn't really seem to have the code for handling protocols like ftp and https. Now I discovered QT has more what I need (http://doc.trolltech.com/2.3/network.html).

It's tempting to make the switch to Qt, but it seems a bit heavy and intersects a lot of Boost functionality. Is it worth learning yet another API (Qt) or can Boost do more than I think?

+10  A: 

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.

Dave Gamble
+1 for libCURL. It is built exactly for this. It's more of a straight C binding (there's a C++ wrapper; haven't used it).
Joe
+3  A: 

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.

Gerald
+2  A: 

The Poco Project has classes for cross-platform HTTP and FTP (and a lot of other stuff). There is overlap with boost. I recently found this, but have not used it.

chrish
A: 

You can use the URLDownloadToFile or URLOpenBlockingStream, although cURL, libcurl are the proper tools for that kind of jobs.

Nick D