AutoIt
AutoIt
Explaining the Rest ClearResponseBodyStream Method
See more Azure Cloud Storage Examples
The ClearResponseBodyStream method would be needed if your applicaiton called SetResponseBodyStream to send the response to a stream for one request, but then wants to subsequently do something else. The application must call ClearResponseBodyStream to no longer send responses to the stream.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oRest = ObjCreate("Chilkat.Rest")
; Connect to the web server
Local $bTls = True
Local $iPort = 443
Local $bAutoReconnect = True
$bSuccess = $oRest.Connect("www.chilkatsoft.com",$iPort,$bTls,$bAutoReconnect)
If ($bSuccess <> True) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
; Setup a file stream for the download
$oFileStream = ObjCreate("Chilkat.Stream")
$oFileStream.SinkFile = "qa_output/starfish.jpg"
; Indicate that the call to FullRequestNoBody should send the response body
; to fileStream if the response status code is 200.
; If a non-success response status code is received, then nothing
; is streamed to the output file and the error response is returned by FullRequestNoBody.
Local $iExpectedStatus = 200
$oRest.SetResponseBodyStream($iExpectedStatus,True,$oFileStream)
Local $sResponseStr = $oRest.FullRequestNoBody("GET","/images/starfish.jpg")
If ($oRest.LastMethodSuccess = False) Then
; Examine the request/response to see what happened.
ConsoleWrite("response status code = " & $oRest.ResponseStatusCode & @CRLF)
ConsoleWrite("response status text = " & $oRest.ResponseStatusText & @CRLF)
ConsoleWrite("response header: " & $oRest.ResponseHeader & @CRLF)
ConsoleWrite("response body (if any): " & $sResponseStr & @CRLF)
ConsoleWrite("---" & @CRLF)
ConsoleWrite("LastRequestStartLine: " & $oRest.LastRequestStartLine & @CRLF)
ConsoleWrite("LastRequestHeader: " & $oRest.LastRequestHeader & @CRLF)
Exit
EndIf
ConsoleWrite("downloaded starfish.jpg" & @CRLF)
; Clear the response body stream previously set in the call to SetResponseBodyStream.
$oRest.ClearResponseBodyStream
; Download something else, but this time send the response body to bd.
$oBd = ObjCreate("Chilkat.BinData")
$bSuccess = $oRest.FullRequestNoBodyBd("GET","/images/penguins.jpg",$oBd)
If ($bSuccess = False) Then
; Examine the request/response to see what happened.
ConsoleWrite("response status code = " & $oRest.ResponseStatusCode & @CRLF)
ConsoleWrite("response status text = " & $oRest.ResponseStatusText & @CRLF)
ConsoleWrite("response header: " & $oRest.ResponseHeader & @CRLF)
ConsoleWrite("response body (if any): " & $oBd.GetString("utf-8") & @CRLF)
ConsoleWrite("---" & @CRLF)
ConsoleWrite("LastRequestStartLine: " & $oRest.LastRequestStartLine & @CRLF)
ConsoleWrite("LastRequestHeader: " & $oRest.LastRequestHeader & @CRLF)
Exit
EndIf
; Save the contents of bd to a file.
$bSuccess = $oBd.WriteFile("qa_output/penguins.jpg")
ConsoleWrite("Success: " & $bSuccess & @CRLF)