0

我正在尝试调用验证请求标头(X-Session-id)的 API 控制器。如何配置 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
        });
4

1 回答 1

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';
};
于 2013-03-18T14:42:24.710 回答