gpt4 book ai didi

rest - Azure 表服务 REST API : JSON format is not supported

转载 作者:行者123 更新时间:2023-12-02 07:41:15 26 4
gpt4 key购买 nike

我尝试使用 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>

这是我的要求:

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

这里是我如何填充请求 header ,从 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";

该表存在且不为空。
请问哪里出了问题?

更新1
正在删除sharedsignature来自请求,即 GET https://<myaccount>.table.core.windows.net/<mytable>(PartitionKey='<mypartition>',RowKey='<myrow>')导致相同的结果。
正在删除Authorization请求的 header 也会导致相同的结果。

更新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>

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

最佳答案

终于明白了!
问题出在我的共享签名中。
在查看它时我发现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>"

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

关于rest - Azure 表服务 REST API : JSON format is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39463917/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com