내가하려는 것은 Azure Storage Rest API List Blob에 연결하는 것입니다. 참조 : http://msdn.microsoft.com/en-us/library/windowsazure/dd135734.aspxAzure - 콜 목록 BLOB에 대한 스토리지 나머지 API
승인 헤더를 지정하기 위해 http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx을 따르려고했지만 403 오류가 발생합니다.
코드 :
Uri address = new Uri("https://account.blob.core.windows.net/$logs?restype=container&comp=list");
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(address);
req.Headers["x-ms-date"] = "2013-09-04";
req.Headers["x-ms-version"] = "2012-02-12";
req.Method = "GET";
string StringToSign = "GET\n"
+ "\n" // content encoding
+ "\n" // content language
+ "\n" // content length
+ "\n" // content md5
+ "\n" // content type
+ "\n" // date
+ "\n" // if modified since
+ "\n" // if match
+ "\n" // if none match
+ "\n" // if unmodified since
+ "\n" // range
+ "x-ms-date: 2013-09-04\nx-ms-version:2012-02-12\n" // headers
+ "/account/blob\ncomp:list\nrestype:container"; // resources
string accountName = "account";
string key = Convert.ToBase64String(Encoding.Default.GetBytes(StringToSign));
req.Headers["Authorization"] = string.Format("SharedKey {0}:{1}", accountName, key);
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
사람이 어떤 실수를 볼 수 있을까요? 키를 생성 할 수있는 도구가 있습니까? 한가지 확실하지 않은 것은 문자열을 올바르게 인코딩/해싱한다는 것입니다.
감사합니다, 최신 코드 앤드류
업데이트. 이 코드는 나에게 금지 된 오류를줍니다.
DateTime dt = DateTime.UtcNow;
string StringToSign = "GET\n"
+ "\n" // content encoding
+ "\n" // content language
+ "\n" // content length
+ "\n" // content md5
+ "\n" // content type
+ "\n" // date
+ "\n" // if modified since
+ "\n" // if match
+ "\n" // if none match
+ "\n" // if unmodified since
+ "\n" // range
+ "x-ms-date: " + dt.ToString("R") + "\nx-ms-version:2012-02-12\n" // headers
+ "/account/$logs\ncomp:list\nrestype:container";
string auth = SignThis(StringToSign, "accountkey", "account");
string method = "GET";
string urlPath = "https://account.blob.core.windows.net/$logs?restype=container&comp=list";
Uri uri = new Uri(urlPath);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = method;
request.Headers.Add("x-ms-date", dt.ToString("R"));
request.Headers.Add("x-ms-version", "2012-02-12");
request.Headers.Add("Authorization", auth);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
}
"키를 생성 할 수있는 도구가 있습니까?"라고 말하면 의심 스럽습니다. 푸른 관리 포털 오른쪽의 푸른 색 저장 페이지에서 키를 가져 오는 중입니까? – paqogomez
예. Azure가 처음입니다. 포털에 액세스 할 수 있습니까? 포털에 나열된 키를 사용하겠습니까? 위의 코드를 통해 키를 생성 하시겠습니까? – andrewb
"StringToSign"으로 무엇을하고 있는지 보았습니다. 그것은 그 예가 당신에게 말하려고하는 것이 아닙니다. 당신은 보낼 가치가 아닌 결과를주고 있습니다. 내가 뭔가를하려고 노력하자. 내가이 모든 코드를 사용하고 있다는 사실을 알기가 어렵습니다. – paqogomez