I have a problem with winhttp.winhttprequest.5.1 & MSXML2.XMLHTTP.6.0 for download large bin file. My code :
;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)
Console :
200
Cache-Control: no-cache, private
Connection: Keep-Alive Date: Thu,25 Aug 2022 07:12:25 GMT
Keep-Alive: timeout=5, max=98
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: text/html;charset=UTF-8
Expires: -1
Server: Apache
Vary: Accept-Encoding
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)
Console :
200
Cache-Control: no-cache, private
Connection: Keep-Alive
Date: Thu, 25 Aug 2022 07:12:25 GMT
Keep-Alive: timeout=5, max=97
Pragma: no-cache
qr> Content-Length: 26683497
Content-Type: text/plain;charset=UTF-8 Expires: 0
Server: Apache
Content-Description: File Transfer
Content-Disposition: attachment;filename=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)
Console :
#Status : 200
#Status Text : OK
#GetAllResponseHeaders :
Cache-Control: no-cache, private
Connection: Keep-Alive
Date: Thu, 25 Aug 2022 07:12:26 GMT
Keep-Alive: timeout=5, max=96
Pragma: no-cache
Content-Length: 26683497
Content-Type: text/plain;charset=UTF-8
Expires: 0
Server: Apache Vary: Accept-Encoding
Content-Description: File Transfer
Content-Disposition: attachment;filename=file.bin
X-Vcap-Request-Id: #######################################UserAgentString : Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)
#URL : https://mylink1-26Mb
#URLCodePage : 65001
#EnableRedirects : True
#UrlEscapeDisableQuery : True
#RevertImpersonationOverSsl : True
#MaxAutomaticRedirects : 10
#MaxResponseHeaderSize : 65536
#MaxResponseDrainSize : 1024000
#EnableHttp1_1 : True
;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
If i use the same script with a 11Mb file, there are no problem !
It's same error with COM : "MSXML2.XMLHTTP.6.0"
Thanks for your help !