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) 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.
#include <C_CkXml.h> #include <C_CkRest.h> #include <C_CkAuthAws.h> #include <C_CkStringBuilder.h> void ChilkatSample(void) { HCkXml xmlToken; BOOL success; HCkRest rest; BOOL bTls; int port; BOOL bAutoReconnect; HCkAuthAws authAws; HCkStringBuilder sbResponse; int statusCode; HCkXml xml; // 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) { printf("%s\n",CkXml_lastErrorText(xmlToken)); CkXml_Dispose(xmlToken); return; } 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) { printf("%s\n",CkRest_lastErrorText(rest)); CkXml_Dispose(xmlToken); CkRest_Dispose(rest); CkAuthAws_Dispose(authAws); CkStringBuilder_Dispose(sbResponse); return; } statusCode = CkRest_getResponseStatusCode(rest); printf("Response status code = %d\n",statusCode); xml = CkXml_Create(); CkXml_LoadSb(xml,sbResponse,TRUE); printf("%s\n",CkXml_getXml(xml)); if (statusCode != 200) { printf("Failed. See error information in the XML.\n"); CkXml_Dispose(xmlToken); CkRest_Dispose(rest); CkAuthAws_Dispose(authAws); CkStringBuilder_Dispose(sbResponse); CkXml_Dispose(xml); return; } CkXml_Dispose(xmlToken); CkRest_Dispose(rest); CkAuthAws_Dispose(authAws); CkStringBuilder_Dispose(sbResponse); CkXml_Dispose(xml); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.