401(未授权)| Cosmos DB 休息 API |来自.net 的休息
401 (Unauthorized) | Cosmos DB rest API | rest-from-.net
我正在为 Cosmos DB rest-from-.net 试用 Table API.
设置endpoint
、masterKey
、databaseId
、collectionId
。我正在使用内部资源 ID。将 x-ms-version
设为 2017-07-29.
在 line 84 之前添加了以下内容。
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("ContentType", "application/json");
现在,它看起来像下面这样:
client.DefaultRequestHeaders.Add("x-ms-date", utc_date);
client.DefaultRequestHeaders.Add("x-ms-version", "2017-07-29");
//LIST all databases
verb = "GET";
resourceType = "dbs";
resourceId = string.Empty;
resourceLink = string.Format("dbs");
authHeader = GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, masterKey, "master", "1.0");
client.DefaultRequestHeaders.Remove("authorization");
client.DefaultRequestHeaders.Add("authorization", authHeader);
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("ContentType", "application/json");
response = client.GetStringAsync(new Uri(baseUri, resourceLink)).Result;
在 GetStringAsync
呼叫中,我收到 401。
HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
我在 Azure Cosmos DB 帐户上拥有参与者角色。
我已经过了this post on stack overflow.
Querying Azure Cosmos DB resources using the REST API 适用于 SQL API 而不是 Table API。但是我已经按照相关提到的部分进行了操作。
Either the Authorization or x-ms-date header is not set. 401 is also returned when the Authorization header is set to an invalid authorization token.
- 阅读Diagnose and troubleshoot Azure Cosmos DB unauthorized exceptions后,我也尝试过使用重新生成的读写主键。
为什么授权失败?
虽然Querying Azure Cosmos DB resources using the REST API describes usage of REST for Cosmos DB, such use of REST is possible only for SQL API not for Gremlin, Cassandra or Table API. Unfortunately, the document doesn't mention that. Hence, the authorization was failing. Instead refer Table Service REST API.
我正在为 Cosmos DB rest-from-.net 试用 Table API.
设置endpoint
、masterKey
、databaseId
、collectionId
。我正在使用内部资源 ID。将 x-ms-version
设为 2017-07-29.
在 line 84 之前添加了以下内容。
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("ContentType", "application/json");
现在,它看起来像下面这样:
client.DefaultRequestHeaders.Add("x-ms-date", utc_date);
client.DefaultRequestHeaders.Add("x-ms-version", "2017-07-29");
//LIST all databases
verb = "GET";
resourceType = "dbs";
resourceId = string.Empty;
resourceLink = string.Format("dbs");
authHeader = GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, masterKey, "master", "1.0");
client.DefaultRequestHeaders.Remove("authorization");
client.DefaultRequestHeaders.Add("authorization", authHeader);
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("ContentType", "application/json");
response = client.GetStringAsync(new Uri(baseUri, resourceLink)).Result;
在 GetStringAsync
呼叫中,我收到 401。
HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
我在 Azure Cosmos DB 帐户上拥有参与者角色。
我已经过了this post on stack overflow.
Querying Azure Cosmos DB resources using the REST API 适用于 SQL API 而不是 Table API。但是我已经按照相关提到的部分进行了操作。
Either the Authorization or x-ms-date header is not set. 401 is also returned when the Authorization header is set to an invalid authorization token.
- 阅读Diagnose and troubleshoot Azure Cosmos DB unauthorized exceptions后,我也尝试过使用重新生成的读写主键。
为什么授权失败?
虽然Querying Azure Cosmos DB resources using the REST API describes usage of REST for Cosmos DB, such use of REST is possible only for SQL API not for Gremlin, Cassandra or Table API. Unfortunately, the document doesn't mention that. Hence, the authorization was failing. Instead refer Table Service REST API.