代码之家  ›  专栏  ›  技术社区  ›  Steve Wasiura

如何防止来自MSXML2的缓存响应。XMLHTTP,vbscript

  •  0
  • Steve Wasiura  · 技术社区  · 7 年前

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

    我正在抓取的文件正在缓存在的子文件夹中 C: \Users\user\AppData\Local\Microsoft\Windows\Internet临时文件\内容。IE5

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

    如果其他人需要此解决方案,我会自行回答

    1 回复  |  直到 7 年前
        1
  •  0
  •   Steve Wasiura    7 年前

    此代码段显示如何从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