2015-11-16 46 views
0

我会改变方法'request'的http拦截器中的内容类型?如何更改HTTP拦截器中的内容类型

我尝试没有成功以下方法:

 config.headers[Content-Type] = 'application/json, text/plain';

有没有解决方案?

代码:

'request': function(config) { 
      config.headers[Content-Type] = 'application/json, text/plain'; 
      return config || $q.when(config); 
     }, 

预先感谢您为您解答!

回答

0

也许你忘了用$ httpProvider注册你的拦截器?

angular.module('myApp', []) 
 
    .config(function($httpProvider) { 
 
    $httpProvider.interceptors.push('myInterceptor'); 
 
});

0

你需要用引号阵列基准键像

config.headers['Content-Type'] 

为它工作。