Restangular not able set default headers


I am trying to send a post request through Restangular. I want to pass json in content so I have added default headers in post request but still it gave 415 Unsupported media Type. When I checked the request headers in browser it still shows text/plain.
This is my function

  this.create = function(data) {
      var deferred = $q.defer();
      var User = Restangular.all('user');, {}, {'Content-Type': 'application/json'})
        .then(function(data) {
          $timeout(function() {
        }, function(error) {
      return deferred.promise;

The GET request works as expected. But I am unable to set content type in header of POST request?

I also tried to set this header globally thorugh

  .config(function($httpProvider, ServiceSettings, RestangularProvider) {

        console.log("urlddd " + ServiceSettings.apiUrl);

        RestangularProvider.setBaseUrl(ServiceSettings.apiUrl + '/api/');

            etag: 'Etag'
            'Content-Type': 'application/json'

But that also dint work. I’ve also tried this but no luck. Can anybody help?



I’ve ended up creating a interceptor and setting each request with that content-type and adding below statement in my config.


Answered By – singhakash

Answer Checked By – Marilyn (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.