2016-05-10 23 views
1

は、これは私のリソース

this.users = $resource(AppConstants.baseUrl); 

で削除これは私がGET要求を行うたび、Content-Typeのは正式から削除され、今私の迎撃

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; 
     } 
    }; 

です要求。私はダミーのデータを渡しても、まだ運がありません。残念ながら、私のREST APIでは、明示的に言及するにはContent-Typeが必要です。

私は何が欠けていますか?

+0

を追加しましたあなたはhttp://stackoverflow.com/a/11876907/1306308 –

+0

を使用して試すことができます私はと比較してそのよりエレガントかつ整頓などのリソースを使用したいです$ http – madhairsilence

答えて

0

その悪名高い角度フォーマット、データがnullの場合は、Content-Typeを削除してください。

回避策は、HTTPインターセプタを変更することです。私の質問でインターセプタを参照すると、私は1行

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 
     } 
関連する問題