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
(Delphi DLL) 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.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, BinData, Rest, Stream; ... procedure TForm1.Button1Click(Sender: TObject); var rest: HCkRest; bTls: Boolean; port: Integer; bAutoReconnect: Boolean; success: Boolean; fileStream: HCkStream; expectedStatus: Integer; responseStr: PWideChar; bd: HCkBinData; begin // 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) then begin Memo1.Lines.Add(CkRest__lastErrorText(rest)); Exit; end; // 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) then begin // Examine the request/response to see what happened. Memo1.Lines.Add('response status code = ' + IntToStr(CkRest_getResponseStatusCode(rest))); Memo1.Lines.Add('response status text = ' + CkRest__responseStatusText(rest)); Memo1.Lines.Add('response header: ' + CkRest__responseHeader(rest)); Memo1.Lines.Add('response body (if any): ' + responseStr); Memo1.Lines.Add('---'); Memo1.Lines.Add('LastRequestStartLine: ' + CkRest__lastRequestStartLine(rest)); Memo1.Lines.Add('LastRequestHeader: ' + CkRest__lastRequestHeader(rest)); Exit; end; Memo1.Lines.Add('downloaded starfish.jpg'); // 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) then begin // Examine the request/response to see what happened. Memo1.Lines.Add('response status code = ' + IntToStr(CkRest_getResponseStatusCode(rest))); Memo1.Lines.Add('response status text = ' + CkRest__responseStatusText(rest)); Memo1.Lines.Add('response header: ' + CkRest__responseHeader(rest)); Memo1.Lines.Add('response body (if any): ' + CkBinData__getString(bd,'utf-8')); Memo1.Lines.Add('---'); Memo1.Lines.Add('LastRequestStartLine: ' + CkRest__lastRequestStartLine(rest)); Memo1.Lines.Add('LastRequestHeader: ' + CkRest__lastRequestHeader(rest)); Exit; end; // Save the contents of bd to a file. success := CkBinData_WriteFile(bd,'qa_output/penguins.jpg'); Memo1.Lines.Add('Success: ' + IntToStr(Ord(success))); CkRest_Dispose(rest); CkStream_Dispose(fileStream); CkBinData_Dispose(bd); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.