doudeng8691 2018-01-25 11:07
浏览 73
已采纳

使用REST API为Azure CosmosDB获取文档

I'm trying CosmosDB Emulator using REST API from PHP. For that I'm using AzureDocumentDB-PHP.

This wrapper library is referring to the MSDN documentation for the REST API. I'm seeing a difference between MSDN documentation and docs.microsoft.com

For example, to retrieve a single document MSDN says use the following syntax:

https://{databaseaccount}.documents.azure.com/dbs/{_rid-db}/colls/{_rid-col}/docs/{_rid-doc}

Whereas the docs.microsoft.com says use the below syntax:

https://{databaseaccount}.documents.azure.com/dbs/{db-id}/colls/{coll-id}/docs/{doc-id}

Note the difference, MSDN uses _rid (system generated id), where as docs.microsoft.com uses just the id (user generated id).

The mentioned PHP library which is using MSDN syntax works fine with the _rid (system generated id). If I try to use the user generated id, I get the following error (for trying to get a db):

{"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
dbs
dbs/db_test
thu, 25 jan 2018 10:28:30 gmt

'

              ActivityId: a43be1a0-c35b-4438-bb83-522204d3f589, 
             Microsoft.Azure.Documents.Common/1.19.102.5"}' (length=388)
  • 写回答

2条回答 默认 最新

  • du94414 2018-01-26 02:19
    关注

    Actually,The MSDN doc and doc.microsoft.com are both cosmosdb REST APIs.

    However , the MSDN doc is stopped updating in July 14, 2015.Obviously, the Azure Cosmos DB REST API is constantly being updated and optimized, as shown in the x-ms-version parameter which is required in the request header.

    The AzureDocumentDB-PHP uses the old version of Azure Cosmos DB REST API which supports _rid of resources , so you can not use it with id of resources. The x-ms-version parameters are different.

    Hope it helps you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100