I am trying to get CSV from a remote server, and they have provided sample code. I am trying to convert this into VFP code and got stuck on one bit.
Not sure how to do the server request "GET" in VFP or if there is any equivalent function to do this?
Full code:
Not sure how to do the server request "GET" in VFP or if there is any equivalent function to do this?
Code:
data = ServerRequest("GET", server & "download/" & what & "/" & page & "?onlyheader=1&apikey=" & apikey, "")
Full code:
Code:
Public Function DownloadAndImport(what As String, tablename As String, Secification As String) As String
Dim data As String
Dim page As Integer
Dim fs As Object ''FileSystemObject
Dim tsOut As Object ''TextStream
'Your Company's API Key goes below
apikey = ""
server = "[URL unfurl="true"]http://xxxxxx.xxx.com.au/"[/URL]
page = 0
lastPage = False
'download the complete file first
Set fs = CreateObject("Scripting.FileSystemObject")
tempFileName = "C:\windows\temp\" & tablename & ".csv"
Set tsOut = fs.CreateTextFile(tempFileName, True)
MsgBox server & "download/" & what & "/" & page & "?onlyheader=0&apikey=" & apikey
End
'Get Header Row
data = ServerRequest("GET", server & "download/" & what & "/" & page & "?onlyheader=1&apikey=" & apikey, "")
If InStr(data, "Error") <> 0 Then
lastPage = True
Else
tsOut.WriteLine data
End If
'Get csv data
While lastPage = False
SysCmd acSysCmdSetStatus, "Downloading To file " & what & ", Page " & page
data = ServerRequest("GET", server & "download/" & what & "/" & page & "?onlyheader=0&apikey=" & apikey, "")
'Check for an Error, meaning it has returned no records
If InStr(data, "Error") <> 0 Then
lastPage = True
Else
tsOut.WriteLine data
page = page + 1
End If
DoEvents
Wend
tsOut.Close
'Import CSV Data into table
SysCmd acSysCmdSetStatus, "Importing File " & what & " to table " & tablename & ", Page " & page
DoCmd.TransferText acImportDelim, Secification, tablename, tempFileName, True
SetAttr tempFileName, vbNormal
' Kill tempFileName
SysCmd acSysCmdClearStatus
End Function