Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Amazon S3 - Delete Bucket (REST API)Deletes an Amazon S3 bucket using the REST API. This example deletes the bucket named "chilkat3".
LOCAL loHttp LOCAL lnSuccess LOCAL loCrypt LOCAL lcCurDateTime LOCAL lcStrToSign LOCAL lcAWSAccessKeyId LOCAL lcAWSSecretAccessKey LOCAL lcSignature LOCAL lcAuthValue LOCAL lcResponseStr LOCAL loXml LOCAL lcEndpoint loHttp = CreateObject('Chilkat.Http') lnSuccess = loHttp.UnlockComponent("Anything for 30-day trial.") IF (lnSuccess <> 1) THEN * Unlock failed. =MESSAGEBOX(loHttp.LastErrorText) QUIT ENDIF loCrypt = CreateObject('Chilkat.Crypt2') lnSuccess = loCrypt.UnlockComponent("Anything for 30-day trial.") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCrypt.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() * Delete the bucket named "chilkat3" lcStrToSign = "DELETE" + [CHR(10) + [CHR(10) + [CHR(10) + lcCurDateTime + [CHR(10) + "/chilkat3/" * We want SHA1 for the HMAC hash algorithm: loCrypt.HashAlgorithm = "sha1" * These must be changed for your account: lcAWSAccessKeyId = "zzzzzzzzzzzzzzzzzzzzz" lcAWSSecretAccessKey = "zzzzzzzzzzzzzzzzzzzzzzzzzzz" * 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 deleted is specified in the Host header. * In this example, the "chilkat3" bucket is deleted loHttp.SetRequestHeader("Host","chilkat3.s3.amazonaws.com") loHttp.SetRequestHeader("Authorization",lcAuthValue) loHttp.SetRequestHeader("Date",lcCurDateTime) * Send the DELETE request. lcResponseStr = loHttp.QuickDeleteStr("http://s3.amazonaws.com/") IF (lcResponseStr = 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 response string, and * a response status of 204. IF (loHttp.LastStatus = 204) THEN =MESSAGEBOX("Bucket deleted!") * Let's check out the response header anyway... ? loHttp.LastResponseHeader ELSE * Is this a temporary redirect? IF (loHttp.LastStatus = 307) THEN * The new endpoint is in the XML contained within responseStr. loXml = CreateObject('Chilkat.Xml') loXml.LoadXml(lcResponseStr) lcEndpoint = loXml.GetChildContent("Endpoint") lcResponseStr = loHttp.QuickDeleteStr(lcEndpoint) IF (loHttp.LastStatus = 204) THEN =MESSAGEBOX("Bucket deleted after redirect!") * Let's check out the response header anyway... ? loHttp.LastResponseHeader ELSE * What happened??? ? "LastStatus: " + loHttp.LastStatus ? "---" ? lcResponseStr ? "---" ? loHttp.LastHeader ? "---" ? loHttp.LastResponseHeader ? "---" ? loHttp.LastErrorText ENDIF ELSE * What response is this??? ? "LastStatus: " + loHttp.LastStatus ? "---" ? lcResponseStr ? "---" * Failed. Show the last request header, response header, * and response body. ? loHttp.LastHeader ? "---" ? loHttp.LastResponseHeader ? "---" ? loHttp.LastErrorText ENDIF 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