2017-03-12 32 views
0

我通過發送查詢documentDB:天青DocumentDB Java的Android的401未經授權

client = new DocumentClient(END_POINT, 
      MASTER_KEY, ConnectionPolicy.GetDefault(), 
      ConsistencyLevel.Session); 

    FeedResponse<Document> documents = client.queryDocuments("/dbs/mydb/colls/mycoll", query, null); 

,然後當我嘗試從服務器讀取響應

for (Document document : documents.getQueryIterable()) 

我得到以下異常:

{"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/mydb/colls/mycoll\nsun, 12 mar 2017 08:40:40 gmt\n\n'\r\nActivityId: f40f31cf-f11c-4052-94b4-992cfdd271f5"} 

請求報頭:

"x-ms-date" -> "Sun, 12 Mar 2017 08:40:40 GMT" 
"x-ms-documentdb-isquery" -> "true" 
"Accept" -> "application/json" 
"Content-Type" -> "application/query+json" 
"authorization" -> "type%3Dmaster%26ver%3D1.0%26sig%3DiQvTEAbWWK8pvHvr9RAqp2kjiechyPp6S5kvxT4g6Kw%3D%0A" 

其他請求的值,我是很重要的:

resourceid = mycoll 
Path = /dbs/mydb/colls/mycoll/docs/ 
resourceType = Document 
IsMedia = false 

請幫助我,我不知道我能做些什麼來解決這個錯誤

回答

0

解決方案從機器人的Base64實施阿帕奇切換。

+0

您好,請您介紹一下您是如何切換到apache實現的?因爲我面臨同樣的問題,但與春天framewok。謝謝。 http://stackoverflow.com/questions/43026784/java-documentdb-unauthorized-access – miskohut

+0

@miskohut以相當醜陋的方式-downlaod documentdb源代碼然後進入apache base64類源代碼並複製粘貼到另一個命名空間這種方式android won'取代它。你可以嘗試它,但我不確定它是春季框架的情況下,因爲它不應該覆蓋documentdb類。無論如何,我放棄了這個解決方案,並切換到提供應用服務的web api服務器作爲中間層。在C#下,一切都像魅力一樣沒有任何問題。另外在這裏發佈未經授權的問題是我對該庫進行修改的最後一步,以使其在android下工作。 – Groth