Global $__HGET[2], _
$__oHttp = ObjCreate( 'WinHttp.WinHttpRequest.5.1' ), _
$__oSvrError = ObjEvent( 'AutoIt.Error', '__OnError' )
; *
Global Const $__iTimeout = 5000
Local $sFile
While Sleep( 40 )
$sFile = _Get( "http://localhost/" )
Select
Case Not $sFile
;Все еще загружается
ContinueLoop
Case $sFile = -1
MsgBox(4096, '', 'Файл недоступен.')
Case Else
FileWrite( "file.txt", $sFile )
EndSelect
ExitLoop
WEnd
#Region Public
Func _Get( $sUrl = '', $sAccept = "text/*" )
Local $vRet = 0
; ---
Select
Case $__HGET[1] <> $sUrl
_Abort()
; -
ContinueCase
Case Not $__HGET[0]
$__oHttp.Open( "GET", $sUrl, 1 )
$__oHttp.SetRequestHeader( "Accept", $sAccept )
$__oHttp.SetRequestHeader( "Accept-Language", "en" )
$__oHttp.SetRequestHeader( "Content-Type","application/x-www-form-urlencoded" )
$__oHttp.SetRequestHeader( "User-Agent", "AutoIt v3" )
$__oHttp.setTimeouts( 0, 0, 0, 0 )
$__oHttp.Send()
; -
$__HGET[0] = TimerInit()
$__HGET[1] = $sUrl
Case TimerDiff( $__HGET[0] ) > $__iTimeout
_Abort()
; -
$vRet = -1
Case Else
Switch $__oHttp.Status
Case 200
$vRet = $__oHttp.ResponseBody
EndSwitch
EndSelect
; -
Return $vRet
EndFunc
Func _Abort( $sSvr = Null )
If $__HGET[1] == $sSvr Or Not $sSvr Then
If $__oHttp.Status <> 200 Then _
$__oHttp.Abort()
; -
$__HGET[0] = 0
$__HGET[1] = 0
EndIf
EndFunc
#EndRegion Public
#Region Events
Func __OnError()
EndFunc
#EndRegion Events