Skip to content

Instantly share code, notes, and snippets.

@nmackenzie
Created September 8, 2013 06:45
Show Gist options
  • Save nmackenzie/6482479 to your computer and use it in GitHub Desktop.
Save nmackenzie/6482479 to your computer and use it in GitHub Desktop.
public void GetEntity(String tableName, String partitionKey, String rowKey)
{
String requestMethod = "GET";
String urlPath = String.Format("{0}(PartitionKey='{1}',RowKey='{2}')", tableName, partitionKey, rowKey);
String storageServiceVersion = "2012-02-12";
String dateInRfc1123Format = DateTime.UtcNow.ToString("R", CultureInfo.InvariantCulture);
String canonicalizedResource = String.Format("/{0}/{1}", AzureStorageConstants.Account, urlPath);
String stringToSign = String.Format(
"{0}\n\n\n{1}\n{2}",
requestMethod,
dateInRfc1123Format,
canonicalizedResource);
String authorizationHeader = Utility.CreateAuthorizationHeader(stringToSign);
Uri uri = new Uri(AzureStorageConstants.TableEndPoint + urlPath);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = requestMethod;
request.Headers.Add("x-ms-date", dateInRfc1123Format);
request.Headers.Add("x-ms-version", storageServiceVersion);
request.Headers.Add("Authorization", authorizationHeader);
request.Headers.Add("Accept-Charset", "UTF-8");
request.Accept = "application/atom+xml,application/xml";
request.Headers.Add("DataServiceVersion", "2.0;NetFx");
request.Headers.Add("MaxDataServiceVersion", "2.0;NetFx");
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
Stream dataStream = response.GetResponseStream();
using (StreamReader reader = new StreamReader(dataStream))
{
String responseFromServer = reader.ReadToEnd();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment