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

时间:2013-03-18 12:23:55

标签: asp.net-web-api jaydata

我正在尝试调用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 个答案:

答案 0 :(得分:2)

有两种方法: 1.如果使用$ data.service初始化上下文,则可以添加带有自定义标题的第三个参数:

$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

或使用prepareRequest

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