Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download file (HTTP) with FoxPro

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

like image 470
Bozho Avatar asked Jan 18 '23 01:01

Bozho


1 Answers

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)

like image 121
Bozho Avatar answered Feb 13 '23 02:02

Bozho