Angular $ httpProvider.interceptor未向请求添加标头

时间:2016-08-20 16:19:10

标签: angularjs angular-http-interceptors

我认为这是一个非常简单的http拦截器。它不起作用。这是代码:

$httpProvider.interceptors.push(['$q', '$cookies', function($q, $cookies) {
    return {

      request: function(config) {

        if(config.url.indexOf('my-api-url.com')!==-1) {
          if($cookies.get('sid')) {
            config.headers.Cookie = 'sid='+$cookies.get('sid');
          }
          console.log(config);
        }

        return config;
      }

    }

  }]);

console.log()正在输出具有“headers”属性的正确外观对象,如下所示:

Accept: "application/json, text/plain, */*"
Cookie: "sid=abcdefg12345thexpectedid54321"

但是当我进入开发者工具中的网络选项卡时,尚未添加Cookie标头!这看起来很简单,我甚至不知道如何开始调试这个内置功能......

0 个答案:

没有答案