[英]Angular $response GET request removes content type
這是我的資源
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
。
我錯過了什么!
弄清楚了。 它是臭名昭着的角度格式,如果數據為null,則刪除Content-Type
解決方法是,更改HTTP攔截器。 在我的問題中提到攔截器,我添加了一行
if (!config.data) {
console.log('Setting content type')
delete config.headers['Content-Type'];
config.headers["Content-Type"] = "application/json;charset=utf-8";
config.data = { dummy : "dummy" }; //Send a dummy data so that your content-type is retained
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.