DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoRest
Boolean iBTls
Integer iPort
Boolean iBAutoReconnect
Variant vFileStream
Handle hoFileStream
Integer iExpectedStatus
String sResponseStr
Variant vBd
Handle hoBd
String sTemp1
Integer iTemp1
Boolean bTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
// Connect to the web server
Move True To iBTls
Move 443 To iPort
Move True To iBAutoReconnect
Get ComConnect Of hoRest "www.chilkatsoft.com" iPort iBTls iBAutoReconnect To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
// Setup a file stream for the download
Get Create (RefClass(cComChilkatStream)) To hoFileStream
If (Not(IsComObjectCreated(hoFileStream))) Begin
Send CreateComObject of hoFileStream
End
Set ComSinkFile Of hoFileStream To "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.
Move 200 To iExpectedStatus
Get pvComObject of hoFileStream to vFileStream
Get ComSetResponseBodyStream Of hoRest iExpectedStatus True vFileStream To iSuccess
Get ComFullRequestNoBody Of hoRest "GET" "/images/starfish.jpg" To sResponseStr
Get ComLastMethodSuccess Of hoRest To bTemp1
If (bTemp1 = False) Begin
// Examine the request/response to see what happened.
Get ComResponseStatusCode Of hoRest To iTemp1
Showln "response status code = " iTemp1
Get ComResponseStatusText Of hoRest To sTemp1
Showln "response status text = " sTemp1
Get ComResponseHeader Of hoRest To sTemp1
Showln "response header: " sTemp1
Showln "response body (if any): " sResponseStr
Showln "---"
Get ComLastRequestStartLine Of hoRest To sTemp1
Showln "LastRequestStartLine: " sTemp1
Get ComLastRequestHeader Of hoRest To sTemp1
Showln "LastRequestHeader: " sTemp1
Procedure_Return
End
Showln "downloaded starfish.jpg"
// Clear the response body stream previously set in the call to SetResponseBodyStream.
Send ComClearResponseBodyStream To hoRest
// Download something else, but this time send the response body to bd.
Get Create (RefClass(cComChilkatBinData)) To hoBd
If (Not(IsComObjectCreated(hoBd))) Begin
Send CreateComObject of hoBd
End
Get pvComObject of hoBd to vBd
Get ComFullRequestNoBodyBd Of hoRest "GET" "/images/penguins.jpg" vBd To iSuccess
If (iSuccess = False) Begin
// Examine the request/response to see what happened.
Get ComResponseStatusCode Of hoRest To iTemp1
Showln "response status code = " iTemp1
Get ComResponseStatusText Of hoRest To sTemp1
Showln "response status text = " sTemp1
Get ComResponseHeader Of hoRest To sTemp1
Showln "response header: " sTemp1
Get ComGetString Of hoBd "utf-8" To sTemp1
Showln "response body (if any): " sTemp1
Showln "---"
Get ComLastRequestStartLine Of hoRest To sTemp1
Showln "LastRequestStartLine: " sTemp1
Get ComLastRequestHeader Of hoRest To sTemp1
Showln "LastRequestHeader: " sTemp1
Procedure_Return
End
// Save the contents of bd to a file.
Get ComWriteFile Of hoBd "qa_output/penguins.jpg" To iSuccess
Showln "Success: " iSuccess
End_Procedure