AnsweredAssumed Answered

HDS HS3 .NET API

Question asked by Chuma Dyasi on Jan 5, 2017
Latest reply on Jan 5, 2017 by Yury Kats

Good day All

 

I am having an issue using the HS3 protocol on the HCP:

 

Below is my code:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.Security;
using Amazon.S3;
using Amazon.S3.Model;
using System.Net;
using System.IO;

namespace HS3_ObjectStore
{
    class Program
    {

        static void Main(string[] args)
        {
            Program prog = new Program();

            string username = "exampleuser";
            string password = "password1";
            string b64Uname;
            string md5Pword;

            var config = new AmazonS3Config();
            config.ServiceURL = "https://tn01.hcp-demo.hcpdemo.com";
            config.UseHttp = false;
            MD5 md5 = System.Security.Cryptography.MD5.Create();
            b64Uname = Convert.ToBase64String(Encoding.UTF8.GetBytes(username));
            md5Pword = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(password))).Replace("-",String.Empty).ToLower();

            var client = new AmazonS3Client(b64Uname,md5Pword,config);

            try
            {
                PutBucketRequest request = new PutBucketRequest();
                request.BucketName = "TestBucket";
                client.PutBucket(request);
            }
            catch (Exception e)
            {
                File.WriteAllText("D:\\Exception.txt", e.ToString());
                Console.WriteLine(b64Uname + " " + md5Pword);
                Console.ReadLine();
            }
           
        }
    }
}

 

And below is the exception that I get:

 

Amazon.S3.AmazonS3Exception: Error making request with Error Code Forbidden and Http Status Code Forbidden. No further error information was returned by the service. ---> Amazon.Runtime.Internal.HttpErrorResponseException: The remote server returned an error: (403) Forbidden. ---> System.Net.WebException: The remote server returned an error: (403) Forbidden.

   at System.Net.HttpWebRequest.GetResponse()

   at Amazon.Runtime.Internal.HttpRequest.GetResponse()

   --- End of inner exception stack trace ---

   at Amazon.Runtime.Internal.HttpRequest.GetResponse()

   at Amazon.Runtime.Internal.HttpHandler`1.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.RedirectHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.Unmarshaller.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.S3.Internal.AmazonS3ResponseHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.ErrorHandler.InvokeSync(IExecutionContext executionContext)

   --- End of inner exception stack trace ---

   at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleException(IExecutionContext executionContext, HttpErrorResponseException exception)

   at Amazon.Runtime.Internal.ExceptionHandler`1.Handle(IExecutionContext executionContext, Exception exception)

   at Amazon.Runtime.Internal.ErrorHandler.ProcessException(IExecutionContext executionContext, Exception exception)

   at Amazon.Runtime.Internal.ErrorHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.CallbackHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.Signer.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.CredentialsRetriever.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.RetryHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.CallbackHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.S3.Internal.AmazonS3KmsHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.EndpointResolver.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.S3.Internal.AmazonS3PostMarshallHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.Marshaller.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.S3.Internal.AmazonS3PreMarshallHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.CallbackHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.S3.Internal.AmazonS3ExceptionHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.MetricsHandler.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.Internal.RuntimePipeline.InvokeSync(IExecutionContext executionContext)

   at Amazon.Runtime.AmazonServiceClient.Invoke[TRequest,TResponse](TRequest request, IMarshaller`2 marshaller, ResponseUnmarshaller unmarshaller)

   at Amazon.S3.AmazonS3Client.PutBucket(PutBucketRequest request)

   at HS3_ObjectStore.Program.Main(String[] args) in c:\Users\Chuma\Documents\Visual Studio 2012\Projects\HS3 ObjectStore\HS3 ObjectStore\Program.cs:line 49

 

Please assist.

 

Regards

 

Chuma

Outcomes