我正在创建一个应用程序。我的服务器是ODATA服务器,我在客户端使用微风。任何人都可以告诉我如何在向服务器发出请求之前添加标题? breeze.config.getAdapterInstance("ajax")
对我不起作用。
var ajaxAdapter = breeze.config.getAdapterInstance('ajax');//,'angular',true);
ajaxAdapter.defaultSettings = {
headers: { "Auth" : "I am not a hacker" },
};
breeze.config.initializeAdapterInstances({ dataService: "webApiOData" });
答案 0 :(得分:2)
webApiOData dataService适配器不使用Breeze中配置的ajax适配器,因此向ajax适配器添加默认标头不起作用。您将不得不配置datajs。见Breeze - Adding headers to request
var oldClient = OData.defaultHttpClient;
var myClient = {
request: function (request, success, error) {
request.headers["Auth"] = "I am not a hacker";
return oldClient.request(request, success, error);
}
};
OData.defaultHttpClient = myClient;
breeze.config.initializeAdapterInstances({ dataService: "webApiOData" });
答案 1 :(得分:0)
我遇到了类似的问题并找到了以下解决方案:
.run(['appConfig', 'breeze', '$http', function (appConfig, breeze, $http) {
$http.defaults.headers.common[appConfig.antiForgeryCookieName] = appConfig.aftoken;
var adapter = (breeze.config.initializeAdapterInstance('dataService', 'webApiOData', true));
adapter.headers[appConfig.antiForgeryCookieName] = appConfig.aftoken;
}