在需要使用VBScript进行身份验证的站点上下载zip文件
我正在尝试使用需要身份验证的VBScript下载ZIP文件。如果你访问该站点,你会注意到它会弹出一个身份验证提示。我遇到的问题是,在这个脚本运行后,ZIP文件太小,无法正常运行,并且已损坏,因此无法打开它 我的想法是下载不起作用 有人知道我做错了什么吗在需要使用VBScript进行身份验证的站点上下载zip文件,vbscript,xmlhttprequest,Vbscript,Xmlhttprequest,我正在尝试使用需要身份验证的VBScript下载ZIP文件。如果你访问该站点,你会注意到它会弹出一个身份验证提示。我遇到的问题是,在这个脚本运行后,ZIP文件太小,无法正常运行,并且已损坏,因此无法打开它 我的想法是下载不起作用 有人知道我做错了什么吗 strHDLocation = "C:\Test\file1.zip" Set xmlHttp = CreateObject("Microsoft.XMLHTTP") xmlHttp.Open "GET", "http:downloadsite
strHDLocation = "C:\Test\file1.zip"
Set xmlHttp = CreateObject("Microsoft.XMLHTTP")
xmlHttp.Open "GET", "http:downloadsite/report-id=123456", False, "myidhere", "mypwhere"
xmlHttp.Send()
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary
objADOStream.Write xmlHttp.ResponseBody
objADOStream.Position = 0 'Set the stream position to the start
Set objFSO = Createobject("Scripting.FileSystemObject")
If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
Set objFSO = Nothing
objADOStream.SaveToFile strHDLocation
objADOStream.Close
Set objADOStream = Nothing
使用
IXmlHttpRequest
时,至少应检查Status
属性,以确保不对返回的内容进行假设
如果xmlHttp.Status=200,则
“请求成功
其他的
“出了点问题
如果结束
请求可能由于某种原因而失败,
ResponseBody
包含失败的响应,而不是预期的ZIP文件。在处理xmlHttp.ResponseBody
之前,检查xmlHttp.ReadyState=4
。还要检查xmlHttp.Status
以确保得到200
HTTP响应。那么我应该循环直到它的值为4吗?我以为Send被阻止了?我这样做了,在Send()之后是4,但仍然是同一个问题。您将它设置为非异步,因此应该阻塞,但可能会发生一些事情,我总是发现最好检查它,无论它是否异步。很可能服务器返回了一个错误,这就是为什么我建议检查xmlHttp.Status
。您是否检查了xmlHttp.Status=200
?啊,忘记了pw上的一个字母!非常感谢。