Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
Amazon S3 - List BucketsDemonstrates how to send a GET request to the Amazon S3 service to list buckets.
CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @sTmp0 nvarchar(4000) DECLARE @http int EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @http, 'UnlockComponent', @success OUT, 'Anything for 30-day trial.' IF @success <> 1 BEGIN -- Unlock failed. EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- The HTTP component now includes a method to generate -- the current date/time in RFC 2616 compliant format. -- Note: The GenTimeStamp method is available as a pre-release (as of 18-June-2008). -- It will become available in the next new version dated after -- 18-June-2008. DECLARE @curDateTime nvarchar(4000) EXEC sp_OAMethod @http, 'GenTimeStamp', @curDateTime OUT PRINT @curDateTime -- The GET operation on the Service endpoint (s3.amazonaws.com) returns a list of all of the buckets owned by the authenticated sender of the request. DECLARE @strToSign nvarchar(4000) ERROR-CONCAT SELECT @strToSign = 'GET' + CHAR(10) + CHAR(10) + CHAR(10) + @curDateTime + CHAR(10) + '/' DECLARE @crypt int EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OAMethod @crypt, 'UnlockComponent', @success OUT, 'Anything for 30-day trial.' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @crypt, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- We want SHA1 for the HMAC hash algorithm: EXEC sp_OASetProperty @crypt, 'HashAlgorithm', 'sha1' -- These must be changed for your account: DECLARE @AWSAccessKeyId nvarchar(4000) SELECT @AWSAccessKeyId = '0PN5J17HBGZHT7JJ3X82' DECLARE @AWSSecretAccessKey nvarchar(4000) SELECT @AWSSecretAccessKey = 'uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o' -- Set the HMAC secret key: EXEC sp_OAMethod @crypt, 'SetHmacKeyString', NULL, @AWSSecretAccessKey -- By setting the charset = "utf-8", the string will be converted -- to utf-8 (internal to the Chilkat component) prior to signing: EXEC sp_OASetProperty @crypt, 'Charset', 'utf-8' -- Indicate that Base64 output is desired: EXEC sp_OASetProperty @crypt, 'EncodingMode', 'base64' DECLARE @signature nvarchar(4000) EXEC sp_OAMethod @crypt, 'HmacStringENC', @signature OUT, @strToSign DECLARE @authValue nvarchar(4000) ERROR-CONCAT SELECT @authValue = 'AWS ' + @AWSAccessKeyId + ':' + @signature EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', @authValue EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Date', @curDateTime DECLARE @xmlResponse nvarchar(4000) EXEC sp_OAMethod @http, 'QuickGetStr', @xmlResponse OUT, 'http://s3.amazonaws.com/' IF @xmlResponse Is NULL BEGIN -- Failed. Show the last request header, response header, -- and response body. EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT PRINT @sTmp0 PRINT '---' EXEC sp_OAGetProperty @http, 'LastResponseHeader', @sTmp0 OUT PRINT @sTmp0 PRINT '---' EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 END ELSE BEGIN -- Success, show the XML response: PRINT @xmlResponse END END GO |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.