Com 使用WinHttp.WinHttpRequest查找检索到的二进制数据的大小

Com 使用WinHttp.WinHttpRequest查找检索到的二进制数据的大小,com,autohotkey,winhttp,winhttprequest,Com,Autohotkey,Winhttp,Winhttprequest,我最近意识到URLDownloadToFile使用IE代理设置。因此,我正在寻找一个替代方案,并发现WinHttp.WinHttpRequest可能会起作用 ResponseBody属性似乎包含获取的数据,我需要将其写入文件。问题是我找不到它的字节大小 有对象的信息,但我找不到它的相关属性 谁能告诉我怎么做 strURL := "http://www.mozilla.org/media/img/sandstone/buttons/firefox-large.png" strFilePath :=

我最近意识到URLDownloadToFile使用IE代理设置。因此,我正在寻找一个替代方案,并发现WinHttp.WinHttpRequest可能会起作用

ResponseBody属性似乎包含获取的数据,我需要将其写入文件。问题是我找不到它的字节大小

有对象的信息,但我找不到它的相关属性

谁能告诉我怎么做

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()   
}

我自己找到了一条路

由于psfa是一个字节数组,因此元素的数量表示其大小

msgbox % psfa.maxindex() + 1    ; 17223 bytes for the example file. A COM array is zero-based so it needs to add one.
但是,要保存存储在safearray中的二进制数据,使用file对象失败。(可能有办法,但我找不到)相反,
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()    
}