我需要帮助aws s3休息授权。
我有下一个代码:
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)禁止。
按照此链接上的步骤完成身份验证:http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html。凭据为:公钥:25496a25b6554f54b5e6私钥:551a656b548e8466f555d540156b5a您只需要使用SHA1的日期,而不需要使用整个请求字符串。日期:2007年3月26日星期一19:37:58 +0000授权人:例如:从九月八日起,每日一次,每日一次
1条答案
按热度按时间erhoui1w1#
您的问题似乎是您的canonicalString和您的HttpWebRequest,我有同样的问题,请参阅此帖子中的解决方案:亚马逊S3 REST API 403错误代码
亚马逊API的文档记录很糟糕