Postman 查询Cosmos数据库的正确授权标头是什么?

Postman 查询Cosmos数据库的正确授权标头是什么?,postman,azure-cosmosdb,Postman,Azure Cosmosdb,我试图查询cosmos db中的文档,但在生成正确的授权头时遇到问题,官方文档中的示例没有显示查询 我正在Postman中尝试使用Javascript将其发布到以下URI: POST https://MyDatabase.documents.azure.com:443/dbs/MyContainer/colls/MyDocuments/docs 使用以下标题: 授权是这样生成的: var now = new Date().toUTCString(); pm.request.headers.

我试图查询cosmos db中的文档,但在生成正确的授权头时遇到问题,官方文档中的示例没有显示查询

我正在Postman中尝试使用Javascript将其发布到以下URI:

POST https://MyDatabase.documents.azure.com:443/dbs/MyContainer/colls/MyDocuments/docs
使用以下标题:

授权是这样生成的:

var now = new Date().toUTCString(); 
pm.request.headers.upsert({key: "x-ms-date", value: now })

var verb = 'POST'; 
var resourceType = "docs"; 
var resourceLink = 'dbs/MyContainer/colls/MyCollection/docs'; 
var text = (verb || "").toLowerCase() + "\n" + 
           (resourceType || "").toLowerCase() + "\n" + 
           (resourceLink || "") + "\n" + 
           now.toLowerCase() + "\n" + 
           "" + "\n"; 


//Hash and Encode by using the masterkey.
var key = CryptoJS.enc.Base64.parse("MyMasterKey"); 
var signature = CryptoJS.HmacSHA256(text, key).toString(CryptoJS.enc.Base64); 
var authToken = encodeURIComponent("type=master&ver=1.0&sig=" + signature);
pm.request.headers.upsert({key: "Authorization", value: authToken })
以下是我得到的错误:

{
    "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: 'post\ndocs\ndbs/MyContainer/colls/MyCollection\nwed, 27 may 2020 19:34:41 gmt\n\n'\r\nActivityId: 724657c7-0532-4c5d-a7ff-c95900ef13cf, Microsoft.Azure.Documents.Common/2.11.0"
}
我猜我的签名创建错误,正确的格式是什么?

我们网站上的文档应该有您想要的


希望这会有所帮助。

对于您的场景,一个必需的修复是您必须删除resourceLink值末尾的“/docs”-将其保留在请求URL中-并且如果您的容器是使用partitionKey创建的,则必须添加以下标题:

'x-ms-documentdb-query-enablecrosspartition': true

我在另一篇文章中提供了解决此问题的答案: