我正在使用$ httpBackend来模拟后端,我希望在收到请求时能够访问标题:
$httpBackend.whenPOST('/movies').respond(function(method, url, data) {
// How do I get access to the headers.
// I want to check the headers and retrieve a token.
var params = angular.fromJson(data),
movie = MoviesDataModel.addOne(params),
movieId = movie.id; // get the id of the new resource to populate the Location field
return [201, movie, { Location: '/movies/' + movieId }];
});
基本上,我想在发送数据之前检查标题中的值。
关于如何做的任何想法?
答案 0 :(得分:0)
来自manual
httpBackend.whenPOST('/movies',data, function(headers){
return headers['Authorization'] == 'xxx';
})
.respond(function(method, url, data) {