1

This is my Resource

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

This is my interceptor

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

Now, whenever I make a GET request, the Content-Type is duly removed from Request. I even passed dummy data but still no luck. Unfortunately, my REST API demands Content-Type to be mentioned explicitly.

What am I missing!

madhairsilence
  • 3,787
  • 2
  • 35
  • 76

1 Answers1

0

Figured it out. Its the infamous angular format, if the data is null, remove the Content-Type

The work around would be , change the HTTP Interceptor. Referring to the interceptor in my question, I added one line

 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
        }
madhairsilence
  • 3,787
  • 2
  • 35
  • 76