Download file (HTTP) with FoxPro

Bozho picture Bozho · Dec 15, 2011 · Viewed 13.3k times · Source

Today I was asked for help with a FoxPro issue, about how to download a file via HTTP.

I found two things: one was a paid ActiveX, and the other one requires libcurl.

Is there a way to do that without anything additional (VFP 8), something like HttpURLConnection in Java? For example by using Microsoft.XMLHTTP

Answer

Bozho picture Bozho · Dec 15, 2011

Two snippets that work, and require no additional files/dlls/flls/etc.

Local loRequest, lcUrl, lcFilename

lcUrl = "http://example.com/foo.zip"
lcFilename = "C:\Temp\PSV.zip"

loRequest = Createobject('MsXml2.XmlHttp')
loRequest.Open("GET",lcUrl,.F.)
loRequest.Send()
StrToFile(loRequest.ResponseBody,lcFilename)

and

lox = CREATEOBJECT("inetctls.inet")
lcSuff = lox.OpenURL("http://whatever.co.uk/suff.htm")
STRTOFILE(lcStuff, "c:\data\myfile.htm")

(taken from here)