2014-10-20 30 views
0

我使用$ 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

manual

httpBackend.whenPOST('/movies',data, function(headers){ 
    return headers['Authorization'] == 'xxx'; 
}) 
.respond(function(method, url, data) { 
得到這個
相關問題