-
Notifications
You must be signed in to change notification settings - Fork 27.4k
How can I set the content-type as application/json for DELETE method in $resource #13290
Comments
This is not Angular-specific, i.e. you can replicate it with "raw" |
@gkalpak, I'm a little confused how this is not angular specific when this is not an issue with angular v1.3.15. I'm in a similar situation as @mdibay1367 where I don't have control over the API I'm hitting, and it is expecting "Content-Type" : "application/json". Any other browser besides IE10/IE11 is not sending a "Content-Type" header at all, but IE10/IE11 insists on attaching a "Content-Type": "text/plain". Again, this issue does not exist with v1.3.15... are we sure this is an issue that should be closed? |
@aghreed , could you, please, provide a live demo (e.g. using CodePen, Plnkr etc) of this working on 1.3.15 ? |
Edit: looks like this issue is being tracked here: #2149 Using Angular v1.4.3. IE11 bug. Not occurring on IE9 or any other browser. Did not check IE10. For what it's worth, I'm having this exact same problem with $http delete. There is a known bug where certain IE versions will treat the "delete" in $http.delete as a JavaScript keyword instead of a method. The workaround is to use $http['delete']. Both of these methods, however, have the exact same issue that mdibay described, as well as $http({method: 'DELETE', url: ...}). I tried explicitly adding 'Content-Type': 'application/json' both on the $httpProvider default headers and in the above object-style $http({headers: {'Content-Type': 'application/json'}}). Also tried lowercased 'content-type' and all permutations of syntax, as suggested by a Stack Overflow post. |
Was able to fix my related problem by setting the message body to null, which removes the Content-Type header in IE11 $http({ |
For me it was enough to prepare following request |
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.
The text was updated successfully, but these errors were encountered: