2017-07-11 36 views
1

我在Android上使用CouchDb + CouchBase Lite,但我在監視複製時遇到了很多麻煩。有時它在所有數據被傳輸之前完成。從CouchDB的數據庫獲取主要數據

在訂單的手,如果你鍵入你的browers(如果使用過程中的couchbd) http://1xx.xxx.xxx.x:5984/your_dataBase你會得到這樣的事情:

{ 「DB_NAME」: 「your_dataBase」, 「doc_count」: 23123, 「doc_del_count」:4812312, 「update_seq」:1050713, 「purge_seq」:0 「compact_running」:假 「DISK_SIZE」:2598379649, 「DATA_SIZE」:1231223, 「instance_start_time」: 「14123213127176」, 「disk_format_version」: 6,「committed_update_seq」:1050713}

或多或少我可以用這個值知道文件數值,所以在我的客戶端代碼我可以比較文件,這個數字我有

「doc_del_count」:4812312

但我不知道如何訪問到json「主」數據,請注意http://184.xxx.xxx.x:xxxx/your_dataBase有一個用戶和一個密碼。

所以我的問題是:我如何獲得CouchDB數據?

回答

1

您必須創建一個基本Authetification與你主數據庫的URL,let's說

xxx.xxx.x.xx:5984/youDB

代碼:

final String basicAuth = 
         Base64.encodeToString("yourUser:yourPass" 
           .getBytes(), Base64.NO_WRAP).replace("\n", ""); 

       URL url = new URL(PreferenceManager.getCouchdbserver()); 
       URLConnection urlc = url.openConnection(); 
       HttpGet httppost = new HttpGet(urlc.getURL().toString()); 
       HttpClient httpclient = new DefaultHttpClient(); 
       httppost.setHeader("Authorization", "Basic "+basicAuth); 
       //HttpReponse response.....and all that stuff