![](/img/trans.png)
[英]$http headers gets added under Access-Control-Request-Headers
[英]Control of headers in a $http request
我為請求中的標題緩存而苦苦掙扎。
我的資源如下:
method: 'GET',
cache: false,
headers: {
session: auth.mySession()
}
提供程序也已配置。
config(['$httpProvider', function($httpProvider) {
if (!$httpProvider.defaults.headers.get) {
$httpProvider.defaults.headers.get = {};
}
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
}]).
實際上,它不起作用。 請求在刪除時與會話一起發送,而在設置時不與會話一起發送。 我必須按Ctrl + F5。
最后,我意識到這不是緩存結果,而是緩存標題本身。
頁眉在頁面初始化階段僅計算一次。 之后,我提供了一個攔截器解決方案,該解決方案始終將有效會話注入請求的標頭中。
config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push('injectingSessionInterceptor');
}]).
service('injectingSessionInterceptor', ['auth', function (auth) {
var ser = this;
ser.request = function (config) {
var session = auth.mySession();
config.headers.session = session;
return config;
};
}]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.