【问题标题】:pouchdb, how to add custom headers to HTTP sync request?pouchdb,如何将自定义标头添加到 HTTP 同步请求?
【发布时间】:2015-03-26 04:15:10
【问题描述】:

如何在 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);

【问题讨论】:

    标签: pouchdb


    【解决方案1】:

    根据the official documentation,您可以使用ajax 选项添加自定义标题(以及更多)。示例:

    var db = new PouchDB('http://example.com/dbname', {
      ajax: {
        cache: false,
        timeout: 10000,
        headers: {
          'X-Some-Special-Header': 'foo'
        },
        username: 'mysecretusername',
        password: 'mysecretpassword'
      }
    });
    

    【讨论】:

      【解决方案2】:

      使用一个有效的对象:

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

      发件人:https://groups.google.com/forum/#!topic/pouchdb/zPQqKzJjQ-M

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-14
        • 1970-01-01
        • 2023-03-12
        • 1970-01-01
        • 2023-03-25
        • 2017-02-15
        相关资源
        最近更新 更多