![pwhr pwhr]()
有人可以告诉如何吗? 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中的二进制数据,使用文件对象将失败. (也许有一种方法,但我找不到它),相反,ADODB.Stream就像一个护身符.strURL := "http://www.mozilla.org/media/img/sandstone/buttons/firefox-large.png"strFilePath := A_ScriptDir "\dl.png"bOverWrite := truepwhr := 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()}I've recently realized that URLDownloadToFile uses the IE proxy setting. So I'm looking for an alternative and found WinHttp.WinHttpRequest may work.It seems the ResponseBody property contains the fetched data and I need to write it to a file. The problem is that I cannot find the byte size of it.http://msdn.microsoft.com/en-us/library/windows/desktop/aa384106%28v=vs.85%29.aspx has the information for the object but I don't find relevant properties for it.Can somebody tell how? 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()} 解决方案 I found a way by myself.Since psfa is a byte array, simply the number of the elements represents its size.msgbox % psfa.maxindex() + 1 ; 17223 bytes for the example file. A COM array is zero-based so it needs to add one.However, to save the binary data stored in a safearray, using the file object was not successful. (There might be a way but I could not find it) Instead, ADODB.Stream worked like a charm.strURL := "http://www.mozilla.org/media/img/sandstone/buttons/firefox-large.png"strFilePath := A_ScriptDir "\dl.png"bOverWrite := truepwhr := 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()} 这篇关于使用WinHttp.WinHttpRequest查找检索到的二进制数据的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 05-29 12:13