DocumentDB-DELETE导致401错误 [英] DocumentDB - DELETE causes 401 error

查看:122
本文介绍了DocumentDB-DELETE导致401错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试对DocumentDB集合执行DELETE动词时,我总是得到401.用于查询/插入/更新的POST可以正常工作,因此我确定计算授权令牌的代码是正确的.但是,我不确定该如何传递资源ID和资源类型.

I always get 401 when I try to execute a DELETE verb against a DocumentDB collection. POST for queries/inserts/updates works fine, so I am sure that my code that calculates the authorization token is correct. What I am not sure however is what I should pass for the resource id and resource type.

payLoad := LowerCase(Verb) + #10+
           LowerCase(resourceType) + #10+
           LowerCase(resourceId) + #10+
           LowerCase(utc_date) + #10 +
           '' + #10; //instead of the "date" header

对于POST(有效),我使用

For the POST (which works), I use

"docs" and "dbs/mydb/mycol/licenses"

对于DELETE,我将"_self"属性的值用于要删除的文档的url.我尝试过可以想到的资源类型和资源ID的任意组合:

For DELETE I use the value of the "_self" property for the url of the doc to be deleted. I tried just about any combination of resource type and resource id I could think of:

docs    dbs/icUoAA==/colls/icUoAKizCgA=/docs
docs    dbs/icUoAA==/colls/icUoAKizCgA=/docs/icUoAKizCgADAAAAAAAAAA==
docs    dbs/icUoAA==/colls/icUoAKizCgA=/docs/icUoAKizCgADAAAAAAAAAA==/
docs/icUoAKizCgADAAAAAAAAAA==   dbs/icUoAA==/colls/icUoAKizCgA=/docs
docs/icUoAKizCgADAAAAAAAAAA==   dbs/icUoAA==/colls/icUoAKizCgA=/docs/icUoAKizCgADAAAAAAAAAA==
etc.

但是删除总是以401失败.我是否需要使用其他内容?

DELETE however always fails with 401. Do I need to use something different?

谢谢!

推荐答案

您可以对DocumentDB提出两种请求.一种基于您定义的"id"属性,另一种基于内部资源ID("_rid").当您使用"id"时,您需要使用整个链接来生成授权令牌,因此对于删除来说,它看起来像

There's two kinds of requests you can make to DocumentDB. One is based on the "id" property that you define, and one based on the internal resource id ("_rid"). When you're using "id", you need to use the entire link for generating the authorization token, so for delete it would look like

delete
docs
dbs/mydb/colls/mycol/docs/cc0d4caabc714aac976c9d0a2e9243ed
sun, 21 aug 2016 20:00:00
 //newline

例如,如果您使用内部资源ID,则只需传递要删除的文档的"_rid",例如

If you're using the internal resource ID, then you just pass in the "_rid" of the document you're trying to delete, for example

delete
docs
icuoakizcgadaaaaaaaaaa== //lowercase
sun, 21 aug 2016 20:00:00
 //newline

可能有助于调试这些错误的一件事是查看与401一起返回的响应正文.它应该包含一条错误消息,告诉您服务器期望的有效负载.

One thing which might help debugging these is looking at the response body that's returned with the 401. It should contain an error message telling you the payload that the server expected.

这篇关于DocumentDB-DELETE导致401错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆