2017-01-09 4 views
1

を使用してAzureストレージテーブルを削除することはできません私はエラーになっています「サーバーの要求を認証に失敗しました。Authorizationヘッダーの値は、署名を含め正しく形成されていることを確認します。は、AzureのRESTのAPI

私は続きますマイクロソフトが提供する認可チュートリアル、Delete TableAuthentication for the Azure Storage Services

何か不足していますか?

enter image description here

+3

あなたはどのように認証ヘッダー値を計算していますか教えてください。私の推測では、そこには簡単なことがあります。 –

+0

@ GauravMantri実際、問題は認証ヘッダー値の計算にありました。 – Sameer

答えて

2

あなたがdelete table via rest apiしたいようです。

次のサンプルは、私の側に正常に動作しますhttps://myaccount.table.core.windows.net/Tables( 'mytableは')

をDELETE、署名を生成するためのコードを参照してください。

string StorageAccount = "account name here"; 
string StorageKey = "account key here"; 
string tablename = "table name"; 

string requestMethod = "DELETE"; 
string mxdate = ""; 
string storageServiceVersion = "2015-12-11"; 

protected void Button1_Click(object sender, EventArgs e) 
{ 
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(string.Format(CultureInfo.InvariantCulture, 
    "https://{0}.table.core.windows.net/Tables('{1}')", 
    StorageAccount, tablename)); 

    req.Method = requestMethod; 

    //specify request header 
    string AuthorizationHeader = generateAuthorizationHeader(); 
    req.Headers.Add("Authorization", AuthorizationHeader); 
    req.Headers.Add("x-ms-date", mxdate); 
    req.Headers.Add("x-ms-version", storageServiceVersion); 
    req.ContentType = "application/json"; 

    req.Accept = "application/json;odata=minimalmetadata"; 

    using (HttpWebResponse response = (HttpWebResponse)req.GetResponse()) 
    { 

    } 
} 

public string generateAuthorizationHeader() 
{ 
    mxdate = DateTime.UtcNow.ToString("R"); 

    string canonicalizedResource = $"/{StorageAccount}/Tables('{tablename}')"; 

    string contentType = "application/json"; 

    string stringToSign = $"{requestMethod}\n\n{contentType}\n{mxdate}\n{canonicalizedResource}"; 

    HMACSHA256 hmac = new HMACSHA256(Convert.FromBase64String(StorageKey)); 

    string signature = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(stringToSign))); 

    String authorization = String.Format("{0} {1}:{2}", 
     "SharedKey", 
     StorageAccount, 
     signature 
     ); 

    return authorization; 
} 
関連する問題