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) S3 List Buckets using an STS Session TokenThis is an example showing how to use an STS session token in an Amazon AWS request. This example will list S3 buckets using a previously obtained session token.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, AuthAws, Rest, Xml, StringBuilder; ... procedure TForm1.Button1Click(Sender: TObject); var xmlToken: HCkXml; success: Boolean; rest: HCkRest; bTls: Boolean; port: Integer; bAutoReconnect: Boolean; authAws: HCkAuthAws; sbResponse: HCkStringBuilder; statusCode: Integer; xml: HCkXml; begin // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // See Get AWS STS Session Token for sample code to get the session token XML. xmlToken := CkXml_Create(); success := CkXml_LoadXmlFile(xmlToken,'qa_data/tokens/aws_session_token.xml'); if (success = False) then begin Memo1.Lines.Add(CkXml__lastErrorText(xmlToken)); Exit; end; rest := CkRest_Create(); // Connect to the Amazon AWS REST server. bTls := True; port := 443; bAutoReconnect := True; success := CkRest_Connect(rest,'s3.amazonaws.com',port,bTls,bAutoReconnect); // Provide AWS credentials for the REST call. authAws := CkAuthAws_Create(); // The purpose of this example is to show how to use the temporary AccessKeyId, SecretAccessKey, and SessionToken. CkAuthAws_putAccessKey(authAws,CkXml__getChildContent(xmlToken,'GetSessionTokenResult|Credentials|AccessKeyId')); CkAuthAws_putSecretKey(authAws,CkXml__getChildContent(xmlToken,'GetSessionTokenResult|Credentials|SecretAccessKey')); CkAuthAws_putServiceName(authAws,'s3'); success := CkRest_SetAuthAws(rest,authAws); CkRest_AddQueryParam(rest,'X-Amz-Security-Token',CkXml__getChildContent(xmlToken,'GetSessionTokenResult|Credentials|SessionToken')); sbResponse := CkStringBuilder_Create(); success := CkRest_FullRequestNoBodySb(rest,'GET','/',sbResponse); if (success <> True) then begin Memo1.Lines.Add(CkRest__lastErrorText(rest)); Exit; end; statusCode := CkRest_getResponseStatusCode(rest); Memo1.Lines.Add('Response status code = ' + IntToStr(statusCode)); xml := CkXml_Create(); CkXml_LoadSb(xml,sbResponse,True); Memo1.Lines.Add(CkXml__getXml(xml)); if (statusCode <> 200) then begin Memo1.Lines.Add('Failed. See error information in the XML.'); Exit; end; CkXml_Dispose(xmlToken); CkRest_Dispose(rest); CkAuthAws_Dispose(authAws); CkStringBuilder_Dispose(sbResponse); CkXml_Dispose(xml); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.