我正在尝试使用Microsoft.XmlHttp
将文本放入网站文件夹结构中的文件中,然后将其与我本地PC上的version.txt
进行比较。如果相同,它会提示它包含相同版本的消息,否则会显示相反的消息。
URL="http://www.example.org/sites/default/files/version.txt"
Set WshShell = WScript.CreateObject("WScript.Shell")
Set http = CreateObject("Microsoft.XmlHttp")
On Error Resume Next
http.open "GET", URL, False
http.send ""
if http.status = 200 Then
server_version = http.responseText
End if
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objClientVersion = objFSO.OpenTextFile("C:\mcgfiles\avp\hash.txt",1)
client_version = objClientVersion.ReadLine
comparison = StrComp(server_version, client_version)
If comparison = 0 Then
Wscript.Echo "the same"
Else
Wscript.Echo "not the same"
End If
有点工作,但每次我尝试从我的服务器更改http://www.example.org/sites/default/files/version.txt的内容时,此脚本仍会获得旧值:例如,之前http://www.example.org/sites/default/files/version.txt的值为123456,当我运行脚本时它获得123456.当我将值更改为654321并运行此脚本时,它仍然获得旧值123456.帮助谢谢
答案 0 :(得分:0)
禁用响应缓存:
http.open "GET", URL, False
http.setRequestHeader "Cache-Control", "no-cache,max-age=0"
http.setRequestHeader "Pragma", "no-cache"
http.send
此外,您可能希望将ReadLine
替换为ReadAll
,因为前者只会读取本地文件的第一行,而HTTP请求会返回整个远程文件。