我需要帮助aws s3 Rest 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);
我需要帮助我在下一个错误:{403} Forbiden。
按照此链接上的步骤完成身份验证: http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html。 凭证是: PublicKey:25496a25b6554f54b5e6 PrivateKey:551a656b548e8466f555d540156b5a 您只需要使用SHA1的日期,不需要使用整个请求字符串。 示例标题: 日期:2007年3月26日星期一19:37:58 +0000 授权:FXST AKIAIOSFODNN7EXAMPLE:frJIUN8DYpKDtOLCwo // yllqDzg =
答案 0 :(得分:0)
您的问题似乎是您的canonicalString和您的HttpWebRequest,我遇到了同样的问题,请参阅此帖中的解决方案:Amazon S3 REST API 403 error c#
令人遗憾的是,亚马逊API的记录很糟糕