【发布时间】:2018-01-18 14:36:47
【问题描述】:
我正在尝试通过 REST API 从 CosmosDB (SQL) 获取文档。 使用 Azure 函数,我根据the code in the documentation 确定授权字符串。
我使用以下参数调用此代码:
GenerateAuthToken("GET", "docs", "dbs/vacancies/colls/items/docs", "masterkey", "master", "1.0");
我只想获取数据库vacancies和集合items中的文档。这些实体存在于 CosmosDB 中(区分大小写匹配),并且该集合中有一个文档。
然后我使用 postman 调用 Cosmos REST API。 我对https://mycosmosdbaccount.documents.azure.com/dbs/vacancies/colls/items/docs 执行 HTTP GET 标题:
x-ms-version : 2017-02-22
Accept: application/json
Authorization: type%3dmaster%26ver%3d1.0%26sig%3dDU1O3I0hMJzF76fedro4M2VnfOhE03aIWgccaVWRBIc%3d
x-ms-date: thu, 18 jan 2018 10:53:23 gmt
我回来了:
{
"code": "Unauthorized",
"message": "The input authorization token can't serve the request. Please check that the expected payload is built as per the protocol, and check the key being used. Server used the following payload to sign: 'get\ndocs\ndbs/vacancies/colls/items\nthu, 18 jan 2018 14:31:43 gmt\n\n'\r\nActivityId: 637276f1-c4ec-4d5d-8199-022d680b31d2, Microsoft.Azure.Documents.Common/1.19.162.2"
}
我已经尝试了大约一百种不同的 resourceLink (dbs/vacancies/colls/items/docs) 和 http get URL 组合,结果始终相同。
请让我知道我做错了什么愚蠢的事情。
【问题讨论】:
-
嗨,现在有更新吗?
-
我的代码和你一样,资源链接不是问题。由于我已经在使用 Azure 函数,所以我只是在其中使用了 dotnet sdk。
-
资源链接在您的帖子中设置为“dbs/vacancies/colls/items/docs”,当您要获取文档时需要将其设置为“dbs/vacancies/colls/items”。
标签: c# rest azure azure-cosmosdb