Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) Explaining the Rest ClearResponseBodyStream MethodSee more Azure Cloud Storage ExamplesThe 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.
Use ChilkatAx-win32.pkg Procedure Test Handle hoRest Boolean iBTls Integer iPort Boolean iBAutoReconnect Boolean iSuccess Variant vFileStream Handle hoFileStream Integer iExpectedStatus String sResponseStr Variant vBd Handle hoBd String sTemp1 Integer iTemp1 Boolean bTemp1 // 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 |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.