我在 Android 上使用 CouchDb
+ CouchBase Lite
但在监视复制时遇到了很多麻烦。有时它会在所有数据传输完成之前完成。
如果您在浏览器上打字(当然如果您使用 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":false,"disk_size":2598379649,"data_size":1231223,"instance_start_time":"14123213127176","disk_format_version":6,"committed_update_seq":1050713}
或多或少我可以知 Prop 有这个值的文档编号,所以在我的客户端代码中我可以将该编号与我拥有的文档进行比较
"doc_del_count":4812312
但我不知道如何访问那个json
“主要”数据,请注意http://184.xxx.xxx.x:xxxx/your_dataBase有用户和密码。
所以我的问题是:如何获取 CouchDB 数据?
最佳答案
你必须用你的主数据库 url 创建一个基本身份验证,比方说
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
关于android - 从 CouchDB 上的数据库获取主要数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45033719/