如何使用同步网关将数据发送到 couchbase 服务器,如何连接到同步网关,URL?

How to send data to couchbase server using sync gateway, how to connect to sync gateway, URL?

我正在 Windows(OS) 上开发 Android 移动应用程序。我想将数据发送到 couchbase 服务器。 我在同步网关的 URL 中犯了错误。我的机器上也有 运行 服务。我已经设置了 couchbase 服务器。

我的 config.json 文件:

{
"log": ["HTTP+"],
"adminInterface": "127.0.0.1:4985",
"interface": "0.0.0.0:4984",
"databases": {
    "db": {
        "server": "http://localhost:8091",
        "bucket": "mobile_data",
        "users": {
            "GUEST": {"disabled": false, "admin_channels": ["*"] }
        }
    }
}
}

我的Android应用代码:

private void initCouchbase() {


// Create replicators to push & pull changes to & from Sync Gateway.
        URL url = null;
        try {
            url = new URL("http://127.0.0.1:4984/db/");
        } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    Replication push = database.createPushReplication(url);
    Replication pull = database.createPullReplication(url);
    push.setContinuous(true);
    pull.setContinuous(true);

 // Start replicators
    push.start();
    pull.start();
}

我正在使用手机进行测试。

我收到与 URL 有关的错误。

Logcat:

01-28 19:21:23.851 28672-28718/com.example.yumnaasim.couchbaseapp W/RemoteRequest: com.couchbase.lite.replicator.RemoteRequest {GET, http://127.0.0.1:4984/db/_local/3259f53711e089457eaed7b5c61d82403d1a98e4}: executeRequest() Exception: java.net.ConnectException: Failed to connect to /127.0.0.1:4984.  url: http://127.0.0.1:4984/db/_local/3259f53711e089457eaed7b5c61d82403d1a98e4
                                                                               java.net.ConnectException: Failed to connect to /127.0.0.1:4984
                                                                                   at okhttp3.internal.io.RealConnection.connectSocket(RealConnection.java:187)
                                                                                   at okhttp3.internal.io.RealConnection.buildConnection(RealConnection.java:170)
                                                                                   at okhttp3.internal.io.RealConnection.connect(RealConnection.java:111)
                                                                                   at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:187)
                                                                                   at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:123)
                                                                                   at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:93)
                                                                                   at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:296)
                                                                                   at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
                                                                                   at okhttp3.RealCall.getResponse(RealCall.java:243)
                                                                                   at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201)
                                                                                   at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
                                                                                   at okhttp3.RealCall.execute(RealCall.java:57)
                                                                                   at com.couchbase.lite.replicator.RemoteRequest.executeRequest(RemoteRequest.java:261)
                                                                                   at com.couchbase.lite.replicator.RemoteRequest.execute(RemoteRequest.java:165)
                                                                                   at com.couchbase.lite.replicator.RemoteRequest.run(RemoteRequest.java:105)
                                                                                   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
                                                                                   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
                                                                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                                   at java.lang.Thread.run(Thread.java:818)
01-28 19:21:23.853 28672-28719/com.example.yumnaasim.couchbaseapp W/RemoteRequest: com.couchbase.lite.replicator.RemoteRequest {GET, http://127.0.0.1:4984/db/_local/3410a851b84016993416af638a20280537838364}: executeRequest() Exception: java.net.ConnectException: Failed to connect to /127.0.0.1:4984.  url: http://127.0.0.1:4984/db/_local/3410a851b84016993416af638a20280537838364
                                                                               java.net.ConnectException: Failed to connect to /127.0.0.1:4984
                                                                                   at okhttp3.internal.io.RealConnection.connectSocket(RealConnection.java:187)
                                                                                   at okhttp3.internal.io.RealConnection.buildConnection(RealConnection.java:170)
                                                                                   at okhttp3.internal.io.RealConnection.connect(RealConnection.java:111)
                                                                                   at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:187)
                                                                                   at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:123)
                                                                                   at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:93)
                                                                                   at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:296)
                                                                                   at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
                                                                                   at okhttp3.RealCall.getResponse(RealCall.java:243)
                                                                                   at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201)
                                                                                   at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
                                                                                   at okhttp3.RealCall.execute(RealCall.java:57)
                                                                                   at com.couchbase.lite.replicator.RemoteRequest.executeRequest(RemoteRequest.java:261)
                                                                                   at com.couchbase.lite.replicator.RemoteRequest.execute(RemoteRequest.java:165)
                                                                                   at com.couchbase.lite.replicator.RemoteRequest.run(RemoteRequest.java:105)
                                                                                   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
                                                                                   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
                                                                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                                   at java.lang.Thread.run(Thread.java:818)
01-28 19:21:25.877 28450-28450/? I/Finsky: [1] com.google.android.finsky.scheduler.ak.a(146): onJobSchedulerWakeup

问题出在您的 Android 应用程序 URL 上。你有 http://127.0.0.1:4984/db/。这会尝试连接到 Android 设备本身。

您需要在那里提供服务器的外部 IP 地址。您使用 "interface": "0.0.0.0:4984" 正确配置了 Sync Gateway。但是请注意,您在 ("GUEST": {"disabled": false, "admin_channels": ["*"] } 上具有来宾访问权限,因此您目前没有安全保障。