0

サラム
私はアンドロイドプロジェクトでクッキーを有効にするためにこれを行いますが、同期ゲートウェイのログリターンでは:

401 login required

session_id("6e2b5106712c0aa3e0048c5b724b302df63d5fbf") is valid for 20 year
couchbase server is in another local pc(192.168.137.137)

    try {
        syncUrl = new URL("http://192.168.137.137:4984/test");
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }

    boolean isSecure = false;
    boolean httpOnly = false;


    Replication pullReplication = database.createPullReplication(syncUrl);
    pullReplication.setContinuous(true);
    pullReplication.setCookie("SyncGatewaySession",
            "6e2b5106712c0aa3e0048c5b724b302df63d5fbf",
            null, 4125798350463L, isSecure, httpOnly);  

    Replication pushReplication = database.createPushReplication(syncUrl);
    pushReplication.setContinuous(true);
    pushReplication.setCookie("SyncGatewaySession",
            "6e2b5106712c0aa3e0048c5b724b302df63d5fbf",
            null, 4125798350463L, isSecure, httpOnly);

    pullReplication.start();
    pushReplication.start();

    pullReplication.addChangeListener(this);
    pushReplication.addChangeListener(this);
4

2 に答える 2

2

問題が解決しました :

try {
    syncUrl = new URL("http://192.168.137.137:4984/test");
} catch (MalformedURLException e) {
    throw new RuntimeException(e);
}

Replication pullReplication = database.createPullReplication(syncUrl);
pullReplication.setContinuous(true);

Replication pushReplication = database.createPushReplication(syncUrl);
pushReplication.setContinuous(true);

Authenticator auth = new BasicAuthenticator(username, password);
pushReplication.setAuthenticator(auth);
pullReplication.setAuthenticator(auth);

pullReplication.start();
pushReplication.start();

pullReplication.addChangeListener(this);
pushReplication.addChangeListener(this);
于 2015-09-28T08:16:31.327 に答える
0

Cookie で提供されるセッション ID を使用する場合は、次のようにします。

http://developer.couchbase.com/documentation/mobile/1.3/develop/guides/authentication/custom-authentication/index.html

Map<String, String> session = new HashMap<String, String>();
session.put("session_id", "904ac010862f37c8dd99015a33ab5a3565fd8447");
session.put("expires", "2015-09-23T17:27:17.555065803+01:00");
session.put("cookie_name", "SyncGatewaySession");

DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Date date = null;
try {
    date = formatter.parse(session.get("expires"));
} catch (ParseException e) {
    e.printStackTrace();
}

Replication pull = database.createPullReplication(syncGatewayURL);
pull.setCookie(session.get("cookie_name"), session.get("session_id"), "/", date, false, false);
pull.start();
于 2016-08-25T06:11:35.343 に答える