Downloading a file from a URL

by Richard Russell, August 2007; amended July 2009

The simplest method of downloading a file (e.g. a web page) from an internet URL is to use the URLDownloadToFileAPI function as described in the main documentation. The following program segment illustrates how to do that:

Unfortunately with early versions of Internet Explorer (pre 4.0) the above code results in a memory leak when used for http downloads (see http://support.microsoft.com/kb/174897). If you need your code to work with such old versions you can use the following routine instead (note that because the HTTP protocol is implied, you must not include the "http://" in the supplied server$):