【发布时间】:2022-09-19 23:04:51
【问题描述】:
我在下载大型 bin 文件时遇到了 winhttp.winhttprequest.5.1 和 MSXML2.XMLHTTP.6.0 问题。 我的代码:
;Droit Admin
#RequireAdmin
;Handler Error
Global $__g_oHTTP_ErrorHandler = ObjEvent("AutoIt.Error", __HTTP_OnError)
$local = @DesktopDir & "\test.bin"
$lien = "https://mylink1-26Mb"
;$lien = "https://mylink2-11Mb"
$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
;First Connection with SSO authenticate
$url = "https://sso.authenticate"
$target = "https://domain"
$body = "USER=ABCD1234&PASSWORD=AZERTY&target=" & $target
$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP.Open("POST", $url, False)
$oHTTP.Send($body)
;Print
ConsoleWrite($oHTTP.Status & @CR)
ConsoleWrite($oHTTP.GetAllResponseHeaders & @CR)
安慰 :
200
缓存控制:无缓存,私有
连接:保持活动日期:2022 年 8 月 25 日星期四 07:12:25 GMT
保活:超时=5,最大值=98
Pragma:无缓存
传输编码:分块
内容类型:text/html;charset=UTF-8
过期:-1
服务器:阿帕奇
变化:接受编码
X-Vcap-Request-Id: ############################;Request HEAD to obtain size file $oHTTP.Open("HEAD", $lien, False) $oHTTP.Send() ;Print $size_cloud_file = $oHTTP.GetResponseHeader("Content-Length") ConsoleWrite($oHTTP.Status & @CR) ConsoleWrite($oHTTP.GetAllResponseHeaders & @CR)安慰 :
200
缓存控制:无缓存,私有
连接:保持活动
日期:格林威治标准时间 2022 年 8 月 25 日星期四 07:12:25
保活:超时=5,最大值=97
Pragma:无缓存
qr> 内容长度:26683497
内容类型:text/plain;charset=UTF-8 过期:0
服务器:阿帕奇
内容描述:文件传输
内容处置:附件;文件名=file.bin
X-Vcap-Request-Id: ########################;Download File $oHTTP.Open("GET", $lien, False) $oHTTP.Send() ;Print all values Consolewrite("#Status : " & $oHTTP.Status & @CR) Consolewrite("#Status Text : " & $oHTTP.StatusText & @CR) Consolewrite("#GetAllResponseHeaders : " & @CR & $oHTTP.GetAllResponseHeaders & @CR) ;Consolewrite("Response Text : " & $oHTTP.ResponseText & @CR) if ($oHTTP.option(0)) Then Consolewrite("#UserAgentString : " & $oHTTP.option(0) & @CR) if ($oHTTP.option(1)) Then Consolewrite("#URL : " & $oHTTP.option(1) & @CR) if ($oHTTP.option(2)) Then Consolewrite("#URLCodePage : " & $oHTTP.option(2) & @CR) if ($oHTTP.option(3)) Then Consolewrite("#EscapePercentInURL : " & $oHTTP.option(3) & @CR) if ($oHTTP.option(4)) Then Consolewrite("#SslErrorIgnoreFlags : " & $oHTTP.option(4) & @CR) if ($oHTTP.option(5)) Then Consolewrite("#SelectCertificate : " & $oHTTP.option(5) & @CR) if ($oHTTP.option(6)) Then Consolewrite("#EnableRedirects : " & $oHTTP.option(6) & @CR) if ($oHTTP.option(7)) Then Consolewrite("#UrlEscapeDisable : " & $oHTTP.option(7) & @CR) if ($oHTTP.option(8)) Then Consolewrite("#UrlEscapeDisableQuery : " & $oHTTP.option(8) & @CR) if ($oHTTP.option(9)) Then Consolewrite("#SecureProtocols : " & $oHTTP.option(9) & @CR) if ($oHTTP.option(10)) Then Consolewrite("#EnableTracing : " & $oHTTP.option(10) & @CR) if ($oHTTP.option(11)) Then Consolewrite("#RevertImpersonationOverSsl : " & $oHTTP.option(11) & @CR) if ($oHTTP.option(12)) Then Consolewrite("#EnableHttpsToHttpRedirects : " & $oHTTP.option(12) & @CR) if ($oHTTP.option(13)) Then Consolewrite("#EnablePassportAuthentication : " & $oHTTP.option(13) & @CR) if ($oHTTP.option(14)) Then Consolewrite("#MaxAutomaticRedirects : " & $oHTTP.option(14) & @CR) if ($oHTTP.option(15)) Then Consolewrite("#MaxResponseHeaderSize : " & $oHTTP.option(15) & @CR) if ($oHTTP.option(16)) Then Consolewrite("#MaxResponseDrainSize : " & $oHTTP.option(16) & @CR) if ($oHTTP.option(17)) Then Consolewrite("#EnableHttp1_1 : " & $oHTTP.option(17) & @CR) if ($oHTTP.option(18)) Then Consolewrite("#EnableCertificateRevocationCheck : " & $oHTTP.option(18) & @CR)安慰 :
#状态:200
#状态文本:好的
#GetAllResponseHeaders :
缓存控制:无缓存,私有
连接:保持活动
日期:格林威治标准时间 2022 年 8 月 25 日星期四 07:12:26
保活:超时=5,最大值=96
Pragma:无缓存
内容长度:26683497
内容类型:text/plain;charset=UTF-8
过期:0
服务器:阿帕奇 变化:接受编码
内容描述:文件传输
内容处置:附件;文件名=file.bin
X-Vcap-Request-Id: ######################################UserAgentString :Mozilla/4.0(兼容;Win32;WinHttp.WinHttpRequest.5)
#URL : https://mylink1-26Mb
#URLCodePage : 65001
#EnableRedirects :真
#UrlEscapeDisableQuery:真
#RevertImpersonationOverSsl :真
#MaxAutomaticRedirects : 10
#MaxResponseHeaderSize :65536
#MaxResponseDrainSize:1024000
#EnableHttp1_1 :真;Copy ResponseBody to bin local file FileDelete($local) $handle = FileOpen($local, 18) FileWrite($handle, $oHTTP.ResponseBody) ;=> ResponseBody empty or not exist FileClose($handle) Func __HTTP_OnError($oError) ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_MyCOMErrFunc如果我对 11Mb 文件使用相同的脚本,则没有问题!
与 COM 相同的错误:“MSXML2.XMLHTTP.6.0”谢谢你的帮助 !
【问题讨论】:
标签: xmlhttprequest autoit winhttprequest