Angular: Custom headers are ignored by $http and $resource. Why?

前端 未结 3 1558
夕颜
夕颜 2021-02-14 21:23

I\'m trying to access a REST service I don\'t control. First problem is that the service doesn\'t include a Access-Control-Allow-Origin header, which is a problem that, if I und

3条回答
  •  名媛妹妹
    2021-02-14 21:59

    The following works for me - however, I do that during "runtime" with $http and I am not using $httpProvider during bootstrapping.

    function SomeCtrl($http) {
    
        $http.defaults.transformRequest.push(function (data, headersGetter) {
            headersGetter().Accept = "application/json, text/javascript";
            return data;
        });
    
    }
    

    Edit

    Here is a working jsFiddle version. Check the request which is done with Developer Tools/Firebug and see that "application/json, text/javascript" is requested.

提交回复
热议问题