如何在 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);
根据官方文档,您可以使用 ajax
选项添加自定义标头(以及更多)。例:
var db = new PouchDB('http://example.com/dbname', {
ajax: {
cache: false,
timeout: 10000,
headers: {
'X-Some-Special-Header': 'foo'
},
username: 'mysecretusername',
password: 'mysecretpassword'
}
});
使用对象有效:
var remoteCouch = new PouchDB('https://serverurl', {headers:{ "APPCID": 1001} });
db.replicate.to(remoteCouch, opts);
寄件人: https://groups.google.com/forum/#!topic/pouchdb/zPQqKzJjQ-M