JayData.js如何传递变量到请求头



我试图调用API控制器,它验证请求的标头(X-Session-id)。如何配置oDataProvider传递变量请求头?

var context = new JayData.SomeEntities({
            name: 'oData',
            oDataServiceHost: 'https://mydomain/RestService',
            headers: { 'X-SessionId': 'f05d1c1e-b1b9-5a2d-2f44-da811bd50bd5' }//How to put value here
        });

有两种方法:1. 如果你用$data初始化你的上下文。服务,然后你可以添加第三个参数与自定义标题:

$data.service('url2yourService', function (factory) {
}, { httpHeaders: { 'X-SessionId': 'f05d1c1e-b1b9-5a2d-2f44-da811bd50bd5' } });

见:http://jaystack.com/blog/what-is-the-difference-between-data.service-and-data.initservice

或使用preperequest

context.prepareRequest = function(cfg){
  cfg[0].headers['X-SessionId'] = 'f05d1c1e-b1b9-5a2d-2f44-da811bd50bd5';
};

相关内容

  • 没有找到相关文章

最新更新