【发布时间】:2016-09-04 21:58:06
【问题描述】:
这是我的资源
this.users = $resource(AppConstants.baseUrl);
这是我的拦截器
return {
request : function(config){
if(blackList.indexOf(config.url.index) != -1){ //Skip API which does not demand JSON type
config.headers["Content-Type"] = "application/json";
}
//Delete content type for GET request
if (!config.data) {
console.log('Setting content type')
delete config.headers['Content-Type'];
config.headers["Content-Type"] = "application/json;charset=utf-8";
}
console.log(config)
return config;
},
response : function(response){
return response;
}
};
现在,每当我发出 GET 请求时,Content-Type 都会从 Request 中适当地删除。我什至通过了虚拟数据,但仍然没有运气。不幸的是,我的 REST API 要求明确提及 Content-Type。
我错过了什么!
【问题讨论】:
-
我想使用资源,因为它比 $http 更优雅和整洁
标签: javascript angularjs get http-headers content-type