2014-06-16 115 views
1

我需要幫助aws s3休息驗證。亞馬遜s3 C#驗證碼

我有下面的代碼:

 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)禁伐。

驗證按照此鏈接上的步驟完成: http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html。 的憑據: 公鑰:25496a25b6554f54b5e6 專用密鑰:551a656b548e8466f555d540156b5a 你只需要使用日期爲SHA1,沒有必要使用整個請求字符串。 實例標題: 日期:星期一,2007年3月26日19時37分58秒+0000 授權:FXST AKIAIOSFODNN7EXAMPLE:frJIUN8DYpKDtOLCwo // yllqDzg =

回答

0

您的問題似乎是你canonicalString和你的HttpWebRequest的,我有同樣的問題,請參閱本文中的解決方案:Amazon S3 REST API 403 error c#

很遺憾亞馬遜API如何被嚴重記錄