Saturday, May 27, 2006

Microsoft.XMLHTTP and cached data

Once I had a problem with Microsoft.XMLHTTP object. It used cached results from previous fetch.
I solved the problem by appending a unique parameter to the URL, which caused the object to fetch the new result each time.
Something like this:
strUrl="http://server.com/servlet/GetData?docid=25C6&unique="+cstr(timer())


----------------------------

Sub Initialize
Dim oHTTP As Variant
Dim strUrl As String
Dim strReturn As String

strUrl = "http://server.com/servlet/GetData?docid=25C6&unique="+cstr(timer())

Set oHTTP = CreateObject("Microsoft.XMLHTTP")
oHTTP.open "GET", strUrl, False, "", ""
oHTTP.send("")
strReturn = oHTTP.responseText
Set oHTTP = Nothing
msgbox strReturn
End Sub

3 comments:

dmanbrock said...

Brilliant. Just the fix I've been looking for!

Unknown said...
This comment has been removed by the author.
dave gellert said...

thanks man you saved my bacon