2014-09-22 196 views
0

我试图在我的网站的文件夹结构中使用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

禁用响应缓存:

http.open "GET", URL, False 
http.setRequestHeader "Cache-Control", "no-cache,max-age=0" 
http.setRequestHeader "Pragma", "no-cache" 
http.send 

此外,您可能希望取代ReadLineReadAll,因为前者只会读取本地文件的第一行,而HTTP请求会返回整个远程文件。

相关问题