Note that there are some explanatory texts on larger screens.

plurals
  1. POAuthorization header in a POST request to Azure Tables
    primarykey
    data
    text
    <p>I've done and tried everything in order to Insert an Entity to an Azure Table, but so far, I still get the same error "StatusCode: 403, ReasonPhrase: 'Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.'"</p> <p>Now, i've tried to use ShareKey and SharedKeyLite (Azure Storage Explorer uses SharedKeyLite)</p> <pre><code>public static async Task&lt;string&gt; InsertEntityAsync(string tableName, Position position) { string uri = @"https://" + Utilities.Account + ".table.core.windows.net/" + tableName; return await Utilities.UploadEntityAsync(tableName,uri,position); } public static async Task&lt;string&gt; UploadEntityAsync(string urlPath, string uri, Position position) { string body = buildBodyForInsertOperation(position); HttpClient request = new HttpClient(); string formatedTime = Authentication.FormatedTime(); request.DefaultRequestHeaders.Add("x-ms-date", formatedTime); //Adding the Authorization header to the request string authorization = Authentication.GetSignedString("POST",formatedTime, urlPath, Utilities.Account, Utilities.Key); request.DefaultRequestHeaders.Add("Authorization", authorization); request.DefaultRequestHeaders.TryAddWithoutValidation("Content-Length", body.Length.ToString()); HttpResponseMessage messageResult = await request.PostAsync(uri, new StringContent(body, UTF8Encoding.UTF8, "application/atom+xml")); return messageResult.ToString(); } public static string GetSignedString(string httpMethod, string time, string urlPath, string account, string key) { String contentMD5 = String.Empty; String contentType = "application/atom+xml"; String canonicalizedResource = String.Format("/{0}/{1}", account, urlPath); String stringToSign = String.Format( "{0}\n{1}\n{2}\n{3}\n{4}", httpMethod, contentMD5, contentType, time, canonicalizedResource); string signedKey = SignThis(stringToSign, key, account); return signedKey; } private static String SignThis(String canonicalizedString,string Key, string Account) { String signature = string.Empty; byte[] unicodeKey = Convert.FromBase64String(Key); using (HMACSHA256 hmacSha256 = new HMACSHA256(unicodeKey)) { Byte[] dataToHmac = System.Text.Encoding.UTF8.GetBytes(canonicalizedString); signature = Convert.ToBase64String(hmacSha256.ComputeHash(dataToHmac)); } String authorizationHeader = String.Format( CultureInfo.InvariantCulture, "{0} {1}:{2}", "SharedKeyLite", Account, signature); return authorizationHeader; } </code></pre> <p>The time parameter is formatted according to what Azure requires, other than that i don't know what else to or try. I've tried to make the request without the httpMethod, without contentMD5, wthout content-type and all sort of combinations, but still.</p> <p>I'm and pretty sure the SignThis(...) method works cause i'm using it to also sign GET requests to query Entities, so any help or words would help me a lot. Thanks</p> <p>/<em>Edited</em>/ I'm attaching the UploadEntityAsync method, in my case i have a Table called Position in Azure, so i'm building the XML, anyway, that's not what's wrong cause i've compared my buided XML with the one of Azure Storage Explorer using Fiddler, and the're o'k. Only problem is the Signature</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload