0

I'm trying to set the content-type as application/json for $resrouce delete action. The only reason that I need to enforce the content-type to application/json is that IE10, and IE11 detects the content-type for DELETE request as plain/text, but all other browsers and older versions of IE detects it as application/json. I have a limitation from back end, which always check for content-type as Json.

Here is how i'm trying to enforce it:

remove: {
    method: 'DELETE', 
    headers: { 'Content-Type': 'application/json; charset=utf-8'}, 
    transformRequest: function(data, headerGetters) {
        headerGetters()['Content-Type'] = 'application/json';
        return angular.toJson(data); 
    }, 
update: {
     method: 'PUT'
}

But this still doesn't work and couldn't set the content-type as json.

diba6122
  • 31
  • 1
  • 7
  • how about checking this question: http://stackoverflow.com/questions/12785386/angularjs-resource-not-setting-content-type – guilhebl Nov 10 '15 at 21:09
  • did you try the same without transformRequest? is it a limitation to use $resource service? – ivamax9 Nov 10 '15 at 21:13
  • I tried without the transformRequest, and nothing changed. Still the IE11 developer tool hows the content-type passed as plain/text and not application/json. – diba6122 Nov 10 '15 at 22:54

1 Answers1

0

TransformRequest is not meant to be used to modify headers. HTTP headers can only be specified when using $http.

See also Angular $resource transformRequest doesn't change Request Header.

Community
  • 1
  • 1
www.admiraalit.nl
  • 5,768
  • 1
  • 17
  • 32
  • transformRequest ability to change request header should be supported in Anagular 1.4 and I'm using the latest version. – diba6122 Nov 10 '15 at 22:57