B4J Question Web server not reading correctly

amorosik

Expert
Licensed User
I'm having serious problems getting a procedure to read text/binary files via HTTP using VBA code within a Microsoft Access procedure to work correctly
The web server used is exactly the demo program as described in the tutorial written by Erel
Below is the B4J code and the VBA code used
The problem is that if I start the download from VBA the first time, the "updater.txt" file located in the "\objects\www" directory of the web server, is read correctly
Then I modify the contents of the source file, updater.txt
If I start the download a second time, it seems to read the updater.txt file correctly, but his content is identical to the original, and therefore does not correspond to the current content
It's as if the VBA code were reading from another web server, but this isn't possible because if I turn off the program that runs the web server, the VBA code correctly fails and reports the impossibility of communicating
So I'm sure the VBA code is addressing the correct web server and attempting to download the same file that's in the web server's www directory
It's as if there's a buffer that holds the information. and when the vba code starts downloading, it downloads the data from this buffer and not actually from the web server

So the question is: how can I force the client and the web server to always download the file currently on the web server (not a buffered version)?


Web server code:
Sub Process_Globals
   Private srvr As Server
End Sub

Sub AppStart (Args() As String)
   srvr.Initialize("srvr")
   srvr.Port = 8888
   srvr.StaticFilesFolder = File.Combine(File.DirApp, "www")
   srvr.AddHandler("/hello", "HelloPage", False)
   srvr.AddHandler("/FormExampleHelper", "FormExampleHelper", False)
   srvr.AddHandler("/FileUpload", "FileUpload", False)
   srvr.Start
   StartMessageLoop
End Sub


Vba client code:
Function ScaricaFileBinario(ByVal url_sorgente As String, ByVal file_destinazione As String) As String
    On Error GoTo eh_ScaricaFileBinario
 
    Dim stream As Object, http As MSXML2.XMLHTTP60

    If UCase$(Left$(url_sorgente, 7)) <> "HTTP://" Then url_sorgente = "http://" & url_sorgente
 
    ' Verifica disponibilità del server con una HEAD request
    Set http = New MSXML2.XMLHTTP60
    http.Open "HEAD", url_sorgente, False
    http.SetRequestHeader "Cache-Control", "no-cache"
    http.Send
 
    If http.Status <> 200 Then
        ScaricaFileBinario = "Server non disponibile. HTTP Status: " & http.Status
        Exit Function
        End If
 
    ' Se il server è disponibile, procedi con il download
    Set http = New MSXML2.XMLHTTP60
    http.Open "GET", url_sorgente, False
    http.SetRequestHeader "Cache-Control", "no-cache"
    http.Send

    If http.Status = 200 Then
        ' Crea lo stream binario
        Set stream = CreateObject("ADODB.Stream")
        stream.Type = 1 ' binario
        stream.Open
        stream.Write http.ResponseBody
        stream.SavetoFile file_destinazione, 2 ' 2 = sovrascrivi se esiste
        stream.Close
        ScaricaFileBinario = "Scaricamento eseguito correttamente"
        Else
        ScaricaFileBinario = "Errore nel download. Codice HTTP: " & http.Status
        End If
 
    Exit Function

eh_ScaricaFileBinario:
    msg_err err.Number, Erl, Error, "ScaricaFileBinario of Modulo modNetwork"
    Resume Next
End Function
 
Last edited:
Top