简体   繁体   中英

How can I set the content-type as application/json for DELETE method in $resource AngularJS

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM