图像GET请求拦截器

时间:2017-02-20 16:17:47

标签: angularjs

我有这个HTTP请求拦截器:

var app = angular.module('mobApp.services');
app.factory('httpRequestInterceptor', function($q, $injector) {
  return {
    request: function(config) {
      var utils = $injector.get('Utils'),
      userDetails = utils.getCurrentUserDetails();
      config.headers.Authorization = "Token 12309123019238";
      if(userDetails) {
        config.headers['X-AccessKey'] = userDetails.apiKey;
        config.headers['X-UserId'] =  userDetails.id;
      }
      return config;
    }
  }

});

app.config(['$httpProvider', function($httpProvider) {  
    $httpProvider.interceptors.push('httpRequestInterceptor');
}]);

它向所有GET / POST请求添加X-标头,但图像GET请求除外。为什么呢?

1 个答案:

答案 0 :(得分:1)

我的猜测是你要拦截来自的请求 select DATEPART(YEAR, OrderDate) AS 'Year', DATEPART(WEEK, OrderDate) AS 'Week', EntityID, COUNT(*) as 'Amount of Orders' FROM tblOrder WHERE DATEPART(YEAR, tblOrder.OrderDate) = 2015 GROUP BY DATEPART(YEAR, OrderDate), DATEPART(WEEK, OrderDate), EntityID 代码

在这种情况下,您需要将<img ng-src="someurl"/>替换为ng-src="someurl"

否则不会使用http-src="someurl"获取这些内容,因此不会传递拦截器

要完成这项工作,您需要一个自定义指令:

$http