如何防止来自 MSXML2.XMLHTTP、vbscript 的缓存响应

how to prevent cached response from MSXML2.XMLHTTP, vbscript

我正在 Windows 7 中用 vbscript 编写 wscript。 该脚本需要从打开的 ftp 服务器获取文件,所以我必须使用 MSXML2.XMLHTTP 对象

我正在抓取的文件缓存在的子文件夹中 C:\Users\user\AppData\Local\Microsoft\Windows\Temporary 互联网 Files\Content.IE5

缓存的文件没有"expires"值,尝试使用setRequestHeader方法设置值似乎没有任何效果。

我会自己回答这个问题,以防其他人需要这个解决方案

此代码片段显示如何从 MSXML2.XMLHTTP 使用的文件夹中删除缓存文件,使用下载文件的概念将具有扩展名“.csv”

<job>
<script language="vbscript">

' use XMLHTTP to grab content from a URL

CMEURL = "ftp://ftp.cmegroup.com/pub/settle/nymex_future.csv"

' the downloaded files are being stored in a subfolder of this folder
filedownloadcachelocation =  "C:\Users\user\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5"

' delete the file before requesting a download

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Dim fileresults 

Dim Directory
Set Directory = fso.GetFolder(filedownloadcachelocation)
Dim subfolders
Set subfolders = Directory.SubFolders
For Each Folder In subfolders
    For Each FileName In Folder.Files
        ' only react if filename extension is csv
        If InStr(FileName , ".csv") Then
            fileresults = fileresults & FileName.Path & vbLf 

            ' delete the file
            If fso.FileExists(FileName.Path) Then
                'WScript.Echo "deleting file " & FileName.Path
                fso.DeleteFile FileName.Path
            End If


        End If ' csv ext
    Next ' each file in folder
Next ' each folder in Content.IE5

WScript.Echo "files found that were deleted = " & VbLf & fileresults

' now continue with downloading the file using XMLHTTP