3

如何在 pouchdb 中向 HTTP 同步请求添加自定义标头?以下不起作用。我正在使用需要额外标头的中间件代理。我需要添加以下 2 个标头(授权和 APPID)。

var opts = {live: true, complete: syncError, withCredentials:true, headers: {Authorization : 'Basic ' + Base64.encode("user:pass"), 'APPID': 1001}};

db.replicate.to(remoteCouch, opts);
4

2 回答 2

3

根据官方文档,您可以使用该ajax选项添加自定义标头(以及更多)。例子:

var db = new PouchDB('http://example.com/dbname', {
  ajax: {
    cache: false,
    timeout: 10000,
    headers: {
      'X-Some-Special-Header': 'foo'
    },
    username: 'mysecretusername',
    password: 'mysecretpassword'
  }
});
于 2015-03-25T20:15:10.340 回答
2

使用对象有效:

var remoteCouch = new PouchDB('https://serverurl', {headers:{ "APPCID": 1001} });
db.replicate.to(remoteCouch, opts);

来自:https ://groups.google.com/forum/#!topic/pouchdb/zPQqKzJjQ-M

于 2014-04-09T09:48:28.210 回答