2014-06-16 2 views
1

aws s3의 도움이 필요합니다.Amazon s3 C# auth

 string url = "http://fxstestcandles.cloudapp.net/pairs/history/eurusd"; 
     HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; 
     request.Method = "GET"; 
     WebHeaderCollection headers = (request as HttpWebRequest).Headers; 
     string httpDate = DateTime.UtcNow.ToString("ddd, dd MMM yyyy HH:mm:ss ") + "+0000"; 

     string canonicalString = "GET\n\n\n " + httpDate + "\n/"; 
     Encoding ae = new UTF8Encoding(); 
     HMACSHA1 signature = new HMACSHA1(); 
     signature.Key = ae.GetBytes("551a656b548e8466f555d540156b5a"); 
     byte[] bytes = ae.GetBytes(canonicalString); 
     byte[] moreBytes = signature.ComputeHash(bytes); 
     string encodedCanonical = Convert.ToBase64String(moreBytes); 
     headers.Add("Authorization", "AWS " + "25496a25b6554f54b5e6" + ":" + encodedCanonical); 
     HttpWebResponse response = request.GetResponse() as HttpWebResponse; 
     Stream stream = response.GetResponseStream() as Stream; 
     byte[] buffer = new byte[32 * 1024]; 
     int nRead =0; 

     MemoryStream ms = new MemoryStream(); 
     do 
     { 
      nRead = stream.Read(buffer, 0, buffer.Length); 
      ms.Write(buffer, 0, nRead); 
     } while (nRead > 0); 


     ASCIIEncoding encoding = new ASCIIEncoding(); 
     string responseString = encoding.GetString(ms.ToArray()); 
     System.Console.Write(responseString); 

내가 도움이 난 다음 오류를 geeting있어 필요합니다 : (403) Forbiden

나는 다음 코드가 있습니다.

이 링크의 단계에 따라 인증을 수행합니다. http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html. 자격 증명은 다음과 같습니다. PublicKey : 25496a25b6554f54b5e6 비공개 키 : 551a656b548e8466f555d540156b5a SHA1의 날짜 만 사용하면 요청 문자열 전체를 사용할 필요가 없습니다. 예 헤더 : 날짜 : 2007년 3월 26일 (월) 19시 37분 58초 0000 인증 : FXST의 AKIAIOSFODNN7EXAMPLE : frJIUN8DYpKDtOLCwo // yllqDzg =

답변

0

귀하의 문제가 보인다는 canonicalString하고 HttpWebRequest를, 내가 가진 동일한 문제가 될 수 있습니다 이 게시물의 솔루션을 참조하십시오 : Amazon S3 REST API 403 error c#

Amazon API가 잘못 문서화 된 것은 슬픈 일입니다.