Asp.net 如何在angularJs中添加WebApi标头

Asp.net 如何在angularJs中添加WebApi标头,asp.net,angularjs,api,web-services,Asp.net,Angularjs,Api,Web Services,我有以下代码从localhost调用WebApi,这非常有效 var app = angular.module('myApp', []); app.controller('employeesController', function ($scope, $http) { $http({ Method: 'GET', url: 'http://localhost:50515/api/employees' }).then(function (result

我有以下代码从localhost调用WebApi,这非常有效

var app = angular.module('myApp', []);
app.controller('employeesController', function ($scope, $http) {
    $http({
        Method: 'GET',
        url: 'http://localhost:50515/api/employees'
    }).then(function (result) {
        $scope.Getemployees = result.data;
    });    
});
我还设置了WebApi服务,并使用postman对其进行了测试。但我想包括WebApi头信息:ApiKey名称和ApiKey值。如何修改上述脚本

url: https://example.api.services/api/XX/v2/employees/all   //url from postman
Key: api-key
value: ba741c13417b7775524dbf0f417cefc4

headers
参数中添加一个具有键值对的对象

$http({
    Method: 'GET',
    url: 'http://localhost:50515/api/employees',
    headers: {
        'api-key': 'ba741c13417b7775524dbf0f417cefc4'
    },
}).then(function (result) {
    $scope.Getemployees = result.data;
});

您可以在
$http
调用中设置标题。请参阅以获取参考。文档还将显示如何在“全局”级别上进行设置,以便您只需在单个位置进行设置(而不丢弃代码)。我如何从浏览器调用它?请参阅api结果browser@Kuku参考这个