问题:在推送过程中,我得到了一个“糟糕的请求”错误和某种身份验证错误,尽管它得到了肯定的响应。
我几乎没有使用CouchDB或Couchbase的经验,但据我所知,您通常会同步Couchbase-Lite与Couchbase同步网关,但由于后者使用CouchDB的复制协议,只要不使用“通道”,仍然可以使用CouchDB。使用CouchDB的复制提到了这里。我不喜欢使用Couchbase同步和Couchbase Server,因为这是一个小型的实验项目,我不需要通道,我的服务器没有足够的资源。
我使用的是CBL-Android0.0.0-501(我认为是最近的一个,已经试用了1.0.3)和CouchDB 1.5.0。
这在我在Android上的主要活动的onCreate方法中被调用:
void minimalPushTest() throws IOException, CouchbaseLiteException {
String databaseName = "cblpushtest";
String couchDbUrl = "http://192.168.4.11:5984";
String userName = "testuser";
String userPw = "testpw";
// initialize database
Manager manager = new Manager(new AndroidContext(this), Manager.DEFAULT_OPTIONS);
Database database = manager.getDatabase(databaseName);
Document document = database.createDocument();
Map<String, Object> data = new HashMap<String, Object>();
data.put("somekey", "sometext");
document.putProperties(data);
// start push replication
Replication replication = database.createPushReplication(new URL(couchDbUrl));
replication.setContinuous(false);
replication.setAuthenticator(new BasicAuthenticator(userName, userPw));
replication.start();
}
这就是CouchDB对用户“testuser”的"/_session“的看法:
{"ok":true,"name":"testuser","roles":["testing"]}
用于“/cblpushtest/_security”的...and:
{"admins":{"names":[],"roles":[]},"members":{"names":["testuser"],"roles":["testing"]}}
下面是Android中的logcat输出:
03-15 23:15:14.999 27429-27429/ W/Sync﹕ [fireTrigger()] => START
03-15 23:15:15.109 27429-27429/ W/Sync﹕ [fireTrigger()] => GO_ONLINE
03-15 23:15:15.199 27429-27546/ E/Sync﹕ com.couchbase.lite.replicator.ReplicationInternal$4@429cbb20 checkSessionAtPath() response: {ok=true, userCtx={name=testuser, roles=[testing]}, info={authentication_db=_users, authentication_handlers=[oauth, cookie, default], authenticated=default}}
03-15 23:15:15.309 27429-27546/ W/Sync﹕ com.couchbase.lite.replicator.ReplicationInternal$9@4291cab0: error getting remote checkpoint
03-15 23:15:15.309 27429-27546/ E/Sync﹕ com.couchbase.lite.replicator.PusherInternal@429c1758: Progress: set error = org.apache.http.client.HttpResponseException: Bad Request
03-15 23:15:15.309 27429-27546/ W/Sync﹕ [fireTrigger()] => STOP_GRACEFUL
03-15 23:15:15.314 27429-27562/ W/Sync﹕ [fireTrigger()] => WAITING_FOR_CHANGES
03-15 23:15:15.314 27429-27562/ W/Sync﹕ [fireTrigger()] => STOP_IMMEDIATE
不知何故,"ok=true“响应显示为错误。
这是couch.log (时钟似乎不同步,但这些是相关的输出):
[Sun, 15 Mar 2015 22:14:32 GMT] [info] [<0.29026.2>] 192.168.4.61 - - GET /_session 200
[Sun, 15 Mar 2015 22:14:32 GMT] [info] [<0.29024.2>] 192.168.4.61 - - GET /_local/3e7d908842481392245906438560f235e9d3138f 400
发布于 2015-03-17 07:58:51
弄明白了:数据库url需要指向实际的数据库,而不仅仅是CouchDB根目录。我以为我之前已经测试过了,但我认为当时我仍然存在身份验证问题,所以我过早地放弃了这个解决方案。
因此,couchDbUrl的正确行是
String couchDbUrl = "http://192.168.4.11:5984/"+databaseName;
..and它可能甚至不需要有相同的名字,但我没有检查。不管怎么说,现在数据被推了。
https://stackoverflow.com/questions/29067253
复制相似问题