how to set custom headers with a $resource action?

前端 未结 5 1614
谎友^
谎友^ 2020-12-03 04:37

with $http, we can do this:

var config = { headers: { \'something\': \'anything\' } };          
$http.get(\'url/to/json\', config)
    .success(function()          


        
5条回答
  •  鱼传尺愫
    2020-12-03 04:59

    To use "Content-Type" header you may need to specify a data body at least for versions around 1.4.7+ due to $http deleting headers without a data body that are === 'content-type'. See #10255 in 1.4.7/angular.js

    I just set "data: false" to spoof it, without specifying a data body:

    $resource('url/to/json', {}, {
        get: {
            method: 'GET',
            data: false,
            headers: { 'something': 'anything' }
        }
    });
    

提交回复
热议问题