Azure 表服务 REST API:不支持 JSON 格式

dek*_*eko 1 rest azure azure-storage azure-table-storage

我尝试使用 REST API 和 C++ 向 Azure 表存储请求一行,但总是出现以下错误:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <cod_e>JsonFormatNotSupported</cod_e>
  <message xml:lang="en-US">JSON format is not supported.
RequestId:0ccb3b9b-0002-0029-3389-0d2fa1000000
Time:2016-09-13T06:39:13.3155742Z</message>
</error>
Run Code Online (Sandbox Code Playgroud)

这是我的要求:

GET https://<myaccount>.table.core.windows.net/<mytable>(PartitionKey='<mypartition>',RowKey='<myrow>')?<sharedsignature>
Run Code Online (Sandbox Code Playgroud)

下面是我如何填充请求标头,来自https://msdn.microsoft.com/en-us/library/dd179428.aspx

std::string sharedAccessSignature("<sharedsignature>");
std::string dateTime(GetDateTime());
std::string stringToSign(dateTime + "\n/" + account + "/" + "<mytable>");
std::string request("(PartitionKey='<mypartition>',RowKey='<myrow>')");
stringToSign += request;
std::string signatureString(HMACSHA256(stringToSign, sharedAccessSignature));

headers["Authorization"] = "SharedKeyLite " + account + ":" + signatureString;
headers["DataServiceVersion"] = "3.0;NetFx";
headers["MaxDataServiceVersion"] = "3.0;NetFx";
headers["x-ms-version"] = "2015-12-11";
headers["x-ms-date"] = dateTime;
headers["Accept"] = "application/json;odata=verbose";
headers["Accept-Charset"] = "UTF-8";
Run Code Online (Sandbox Code Playgroud)

该表存在且不为空。
请指教有什么问题吗?

更新 1从请求中
删除,即导致相同的结果。从请求中 删除标头也会导致相同的结果。sharedsignatureGET https://<myaccount>.table.core.windows.net/<mytable>(PartitionKey='<mypartition>',RowKey='<myrow>')
Authorization

更新 2
放入https://<myaccount>.table.core.windows.net/<mytable>(PartitionKey='<mypartition>',RowKey='<myrow>')?<sharedsignature>浏览器中会产生有效的响应,但采用Atom格式。

<?xml version="1.0" encoding="utf-8"?>
<entry 
  xml:base="https://<myaccount>.table.core.windows.net/" 
  xmlns="http://www.w3.org/2005/Atom" 
  xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" 
  xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" 
  m:etag="W/&quot;datetime'2016-09-13T05%3A29%3A51.211538Z'&quot;">
  <id>https://<myaccount>.table.core.windows.net/<mytable> (PartitionKey='<mypartition>',RowKey='<myrow>')</id>
  <category term="<myaccount>.<mytable>" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
  <link rel="edit" title="<mytable>" href="<mytable> (PartitionKey='<mypartition>',RowKey='<myrow>')" />
  <title />
  <updated>2016-09-13T11:25:19Z</updated>
  <author><name /></author>
  <content type="application/xml">
    <m:properties>
      <d:PartitionKey><mypartition></d:PartitionKey>
      <d:RowKey><myrow></d:RowKey>
      <d:Timestamp m:type="Edm.DateTime">2016-09-13T05:29:51.211538Z</d:Timestamp>
      <d:Score m:type="Edm.Int32">1050</d:Score>
    </m:properties>
  </content>
</entry>
Run Code Online (Sandbox Code Playgroud)

更新3
使用调查情况curl我发现添加Accept: application/json;odata=fullmetadata到请求标头会导致上述错误。标头中的默认值Accept */*会生成有效的Atom响应。

dek*_*eko 5

终于,明白了!
问题出在我的共享签名中。
在查看它时,我发现了sv=2012-02-12一部分,并假设它意味着 API 版本。引入 JSON 支持之前的版本!我创建了一个新的共享签名,并最终使用以下curl命令获得了JSON。
curl -v -H "Accept: application/json;odata=nometadata" -H "x-ms-version: 2015-12-11" "https://<myaccount>.table.core.windows.net/<mytable>(PartitionKey='<mypartition>',RowKey='<myrow>')?<mysharedsignature>"

所以,对于以后遇到同样问题的大家:请先检查一下你的签名!