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
(C) 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.
#include <C_CkRest.h> #include <C_CkStream.h> #include <C_CkBinData.h> void ChilkatSample(void) { HCkRest rest; BOOL bTls; int port; BOOL bAutoReconnect; BOOL success; HCkStream fileStream; int expectedStatus; const char *responseStr; HCkBinData bd; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. rest = CkRest_Create(); // Connect to the web server bTls = TRUE; port = 443; bAutoReconnect = TRUE; success = CkRest_Connect(rest,"www.chilkatsoft.com",port,bTls,bAutoReconnect); if (success != TRUE) { printf("%s\n",CkRest_lastErrorText(rest)); CkRest_Dispose(rest); return; } // Setup a file stream for the download fileStream = CkStream_Create(); CkStream_putSinkFile(fileStream,"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. expectedStatus = 200; CkRest_SetResponseBodyStream(rest,expectedStatus,TRUE,fileStream); responseStr = CkRest_fullRequestNoBody(rest,"GET","/images/starfish.jpg"); if (CkRest_getLastMethodSuccess(rest) == FALSE) { // Examine the request/response to see what happened. printf("response status code = %d\n",CkRest_getResponseStatusCode(rest)); printf("response status text = %s\n",CkRest_responseStatusText(rest)); printf("response header: %s\n",CkRest_responseHeader(rest)); printf("response body (if any): %s\n",responseStr); printf("---\n"); printf("LastRequestStartLine: %s\n",CkRest_lastRequestStartLine(rest)); printf("LastRequestHeader: %s\n",CkRest_lastRequestHeader(rest)); CkRest_Dispose(rest); CkStream_Dispose(fileStream); return; } printf("downloaded starfish.jpg\n"); // Clear the response body stream previously set in the call to SetResponseBodyStream. CkRest_ClearResponseBodyStream(rest); // Download something else, but this time send the response body to bd. bd = CkBinData_Create(); success = CkRest_FullRequestNoBodyBd(rest,"GET","/images/penguins.jpg",bd); if (success == FALSE) { // Examine the request/response to see what happened. printf("response status code = %d\n",CkRest_getResponseStatusCode(rest)); printf("response status text = %s\n",CkRest_responseStatusText(rest)); printf("response header: %s\n",CkRest_responseHeader(rest)); printf("response body (if any): %s\n",CkBinData_getString(bd,"utf-8")); printf("---\n"); printf("LastRequestStartLine: %s\n",CkRest_lastRequestStartLine(rest)); printf("LastRequestHeader: %s\n",CkRest_lastRequestHeader(rest)); CkRest_Dispose(rest); CkStream_Dispose(fileStream); CkBinData_Dispose(bd); return; } // Save the contents of bd to a file. success = CkBinData_WriteFile(bd,"qa_output/penguins.jpg"); printf("Success: %d\n",success); CkRest_Dispose(rest); CkStream_Dispose(fileStream); CkBinData_Dispose(bd); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.