Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Amazon S3 - Create Bucket with PUT RequestDemonstrates how to create an Amazon S3 bucket by sending a PUT HTTP request.
LOCAL loHttp LOCAL lnSuccess LOCAL lcCurDateTime LOCAL lcStrToSign LOCAL loCrypt LOCAL lcAWSAccessKeyId LOCAL lcAWSSecretAccessKey LOCAL lcSignature LOCAL lcAuthValue LOCAL lcXmlResponse loHttp = CreateObject('Chilkat.Http') lnSuccess = loHttp.UnlockComponent("Anything for 30-day trial.") IF (lnSuccess <> 1) THEN * Unlock failed. =MESSAGEBOX(loHttp.LastErrorText) QUIT ENDIF * 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. lcCurDateTime = loHttp.GenTimeStamp() =MESSAGEBOX(lcCurDateTime) * The PUT request operation with a bucket URI creates a new bucket. lcStrToSign = "PUT" + [CHR(10) + [CHR(10) + [CHR(10) + lcCurDateTime + [CHR(10) + "/chilkat/" loCrypt = CreateObject('Chilkat.Crypt2') lnSuccess = loCrypt.UnlockComponent("Anything for 30-day trial.") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCrypt.LastErrorText) QUIT ENDIF * We want SHA1 for the HMAC hash algorithm: loCrypt.HashAlgorithm = "sha1" * These must be changed for your account: lcAWSAccessKeyId = "zzzzzzzzzzzzzzzzzzzzz" lcAWSSecretAccessKey = "zzzzzzzzzzzzzzzzzzzzzzzzzzzz" * Set the HMAC secret key: loCrypt.SetHmacKeyString(lcAWSSecretAccessKey) * By setting the charset = "utf-8", the string will be converted * to utf-8 (internal to the Chilkat component) prior to signing: loCrypt.Charset = "utf-8" * Indicate that Base64 output is desired: loCrypt.EncodingMode = "base64" lcSignature = loCrypt.HmacStringENC(lcStrToSign) lcAuthValue = "AWS " + lcAWSAccessKeyId + ":" + lcSignature * The bucket to be created is specified in the Host header. * In this example, the "chilkat" bucket is created: loHttp.SetRequestHeader("Host","chilkat.s3.amazonaws.com") loHttp.SetRequestHeader("Authorization",lcAuthValue) loHttp.SetRequestHeader("Date",lcCurDateTime) loHttp.SetRequestHeader("Content-Length","0") lcXmlResponse = loHttp.QuickPutStr("http://s3.amazonaws.com/") IF (lcXmlResponse = NULL ) THEN * Failed. Show the last request header, response header, * and response body. ? loHttp.LastHeader ? "---" ? loHttp.LastResponseHeader ? "---" ? loHttp.LastErrorText ELSE * Success is indicated by an empty xmlResponse string, and * a response status of 200. IF (loHttp.LastStatus = 200) THEN =MESSAGEBOX("Bucket created!") * Let's check out the response header anyway... ? loHttp.LastResponseHeader ELSE * Failed. Show the last request header, response header, * and response body. ? loHttp.LastHeader ? "---" ? loHttp.LastResponseHeader ? "---" ? loHttp.LastErrorText ENDIF ENDIF |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser