मैं सी # के माध्यम से आरईएसटी एपीआई का उपयोग कर एस 3 से फाइल लाने के लिए कुछ कोड प्राप्त करने की कोशिश कर रहा हूं। मैंने अन्य लोगों को समान चीजें करने के लिए देखा है लेकिन किसी कारण से मुझे 403 त्रुटि मिल रही है। मैंने एडब्ल्यूएस एसडीके के साथ एक ही काम करने की कोशिश की है। नेट और यह काम करता है इसलिए मुझे लगता है कि मैं प्राधिकरण शीर्षलेख बना रहा हूं।अमेज़ॅन एस 3 आरईएसटी एपीआई 403 त्रुटि सी #
क्या कोई इस पर कोई प्रकाश डालने में सक्षम है?
string awsAccessId = "***";
string awsSecretKey = "***";
string bucketName = "thebucket";
string httpDate = DateTime.Now.ToString("ddd, dd MMM yyyy HH:mm:ss +0000\n");
string canonicalString = "GET\n"
+ "\n"
+ "\n"
+ "x-amz-date:" + httpDate + "\n"
+ "/" + bucketName + "/readme.txt";
// now encode the canonical string
Encoding ae = new UTF8Encoding();
// create a hashing object
HMACSHA1 signature = new HMACSHA1();
// secretId is the hash key
signature.Key = ae.GetBytes(awsSecretKey);
byte[] bytes = ae.GetBytes(canonicalString);
byte[] moreBytes = signature.ComputeHash(bytes);
// convert the hash byte array into a base64 encoding
string encodedCanonical = Convert.ToBase64String(moreBytes);
// Send the request
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://" + bucketName +".s3.amazonaws.com/readme.txt");
request.Headers.Add("x-amz-date", httpDate);
request.Headers.Add("Authorization", "AWS " + awsAccessId + ":" + encodedCanonical);
request.Method = "GET";
// Get the response
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Console.WriteLine(response.StatusCode);
Console.Read();
यदि यह काम करता है तो एसडीके का उपयोग क्यों नहीं करें? –
मैं इसे अपने सुझाव के लिए धन्यवाद एक एसएसआईएस स्क्रिप्ट कार्य – MarkJ