Greg-A
Greg-A

Reputation: 862

How to change content-type in http-interceptor

I would change the content-type in http- interceptor for the method ' request' ?

I tried the following method without success :

 config.headers[Content-Type] = 'application/json, text/plain';

Is there a solution ?

code :

'request': function(config) {
            config.headers[Content-Type] = 'application/json, text/plain';
            return config || $q.when(config);
        },

Thank you in advance for your answers !

Upvotes: 0

Views: 803

Answers (2)

Roope Hakulinen
Roope Hakulinen

Reputation: 7405

You need to wrap the array reference key with quotes like

config.headers['Content-Type']

for it to work.

Upvotes: 1

Guenter Guckelsberger
Guenter Guckelsberger

Reputation: 940

Maybe you forgot to register your interceptor with $httpProvider?

angular.module('myApp', [])
  .config(function($httpProvider) {
  $httpProvider.interceptors.push('myInterceptor');
 });

Upvotes: 0

Related Questions