Created
July 12, 2014 17:22
-
-
Save JerryBian/064dbe77502c4d81b8d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void SetServiceProperties() | |
{ | |
var requestMethod = "PUT"; | |
var requestBody = string.Format("<StorageServiceProperties><Cors><CorsRule><AllowedOrigins>{0}</AllowedOrigins><AllowedMethods>{1}</AllowedMethods><MaxAgeInSeconds>{2}</MaxAgeInSeconds><ExposedHeaders>{3}</ExposedHeaders><AllowedHeaders>{4}</AllowedHeaders></CorsRule></Cors></StorageServiceProperties>", "http://www.baidu.com", "GET,PUT", 200, "x-ms-meta-*", "x-ms-meta-data*,x-ms-meta-target,x-ms-meta-source"); | |
var storageServiceVersion = "2014-02-14"; | |
var date = DateTime.UtcNow.ToString("R"); | |
var canonicalizedHeaders = string.Format("x-ms-date:{0}\nx-ms-version:{1}", date, storageServiceVersion); | |
var canonicalizedResource = string.Format("/{0}\ncomp:properties\nrestype:service", StorageAccount); | |
var stringToSign = string.Format("{0}\n\n\n{1}\n\ntext/plain; charset=utf-8\n\n\n\n\n\n\n{2}\n{3}", requestMethod, requestBody.Length, canonicalizedHeaders, canonicalizedResource); | |
var authorizationHeader = GetAuthorizationHeader(stringToSign); | |
using (var httpClient = new HttpClient()) | |
{ | |
httpClient.BaseAddress = new Uri(QueueEndPoint); | |
httpClient.DefaultRequestHeaders.Clear(); | |
httpClient.DefaultRequestHeaders.Add("x-ms-date", date); | |
httpClient.DefaultRequestHeaders.Add("x-ms-version", storageServiceVersion); | |
httpClient.DefaultRequestHeaders.Add("Authorization", authorizationHeader); | |
var result = httpClient.PutAsync("?restype=service&comp=properties", new StringContent(requestBody)); | |
result.Wait(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment