我最近意识到 URLDownloadToFile 使用 IE 代理设置。所以我正在寻找替代方案,发现 WinHttp.WinHttpRequest 可能有效。
ResponseBody 属性似乎包含获取的数据,我需要将其写入文件。问题是我找不到它的字节大小。
http://msdn.microsoft.com/en-us/library/windows/desktop/aa384106%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/windows/desktop/aa384106%28v=vs.85%29.aspx有该对象的信息,但我没有找到它的相关属性。
有人能告诉怎么做吗?
strURL := "http://www.mozilla.org/media/img/sandstone/buttons/firefox-large.png"
strFilePath := A_ScriptDir "\dl.jpg"
pwhr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
pwhr.Open("GET", strURL)
pwhr.Send()
if (psfa := pwhr.ResponseBody ) {
oFile := FileOpen(strFilePath, "w")
; msgbox % ComObjType(psfa) ; 8209
oFile.RawWrite(psfa, strLen(psfa)) ; not working
oFile.Close()
}
我自己找到了办法。
Since psfa
是一个字节数组,简单地用元素的数量代表它的大小。
msgbox % psfa.maxindex() + 1 ; 17223 bytes for the example file. A COM array is zero-based so it needs to add one.
但是,要保存存储在 safearray 中的二进制数据,使用文件对象并不成功。 (可能有办法,但我找不到)相反,ADODB.Stream
就像魅力一样。
strURL := "http://www.mozilla.org/media/img/sandstone/buttons/firefox-large.png"
strFilePath := A_ScriptDir "\dl.png"
bOverWrite := true
pwhr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
pwhr.Open("GET", strURL)
pwhr.Send()
if (psfa := pwhr.ResponseBody ) {
pstm := ComObjCreate("ADODB.Stream")
pstm.Type() := 1 ; 1: binary 2: text
pstm.Open()
pstm.Write(psfa)
pstm.SaveToFile(strFilePath, bOverWrite ? 2 : 1)
pstm.Close()
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)