1

I'm setting up a client code written VBScript which probes a text file on a server with HTTP GET requests. The client has actions related to each HTTP response text.

While doing so in a While True loop, the first request returns the correct value. All the preceding requests return the same value the first response did.

The content of the file changes while the HTTP request doesn't seem to leave the client while sniffing packets. Code:

function checkLog(url)
    Dim WshShell, http
    Set WshShell = CreateObject("WScript.Shell")
    Set http = CreateObject("Microsoft.XmlHttp")
    On Error Resume Next
    http.open "GET" , url, False
    http.send ""
    checkLog = http.responseText
End function


Dim lastVal = "2"
Dim logResult = "2"
Do While True
    logResult = checkLog("http://10.0.0.3/log.txt")
    If logResult <> lastVal Then
        If logResult = "0" Then
            ' Go Func 1
            MsgBox "Got 0"
            lastVal = logResult
        End If

        If logResult = "1" Then
            ' Go Func 2
            MsgBox "Got 1"
            lastVal = logResult
        End If
    End If
    Sleep 5
LOOP

I expect that a packet will be sent every 5 seconds. Thanks!

elonmuskor
  • 11
  • 2
  • The loop doesn’t fail, the request is being cached. Disable caching via the request headers or by added a token value to the query-string which is unique each time *(A string format of `Now()` works well unless you’re returning more than a request a second)*. – user692942 Aug 25 '19 at 20:43

1 Answers1

1

Disable caching of the HTTP response.

Set req = CreateObject("Msxml2.XmlHttp")
On Error Resume Next
req.Open "GET", url, False
req.SetRequestHeader "Cache-Control", "no-cache"
req.Send ""
checkLog = req.ResponseText
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • After doing a little research about the caching mechanism of HTTP, sending a request with the "no-cache" header will work only upon servers which support responding back with the "no-cache" header. python http.server (a.k.a SimpleHTTPServer) does not support it. In order for it to support that refer to this link: https://stackoverflow.com/questions/12193803/invoke-python-simplehttpserver-from-command-line-with-no-cache-option. – elonmuskor Aug 27 '19 at 10:57
  • @elonmuskor Webservers should normally do that. And what does Python's SimpleHTTPServer not supporting it out of the box have to do with your question? – Ansgar Wiechers Aug 27 '19 at 11:06
  • I tried the solution you gave me, and still, it didn't work for me. Then I figured out it is because of me using python's SimpleHTTPServer, which does not support it. Just making it clear for future morons like me :) – elonmuskor Aug 27 '19 at 11:17