How can I retrieve the response header from a GET request?
I have a service function that returns a promise. In my Controller, I resolve the promise and in the .then function, I need to access the content type from the response header.
I attempted to use the "headers" parameter, and tried to display it with console.log(headers()), but I encountered the error "headers() is not a function" in my console.
Here is My Service :
.factory('GetResultFile',
['$http', '$q',
function ($http, $q) {
var service = {};
service.getResult = function(id, rid) {
var deferred = $q.defer();
$http
.get('http://localhost:9999/v1/jmeter/' + id + '/results/' + rid, {cache: false})
.then(function(data, status, headers, config) {
if(data.status == 200) {
console.log(data.status);
deferred.resolve(data);
}
else {
deferred.reject(data);
}
});
return deferred.promise;
}
return service;
}]);
And here is the controller:
$scope.getResult = function(rid) {
console.log($scope.id);
GetResultFile.getResult($scope.id, rid)
.then(function(data, headers) {
//console.log(headers.Content-type);
console.log(headers());
console.log(data);
console.log("Download succeed");
console.log(data.status);
var file = new Blob([data.data], {type: 'text/plain;charset=utf-8'});
FileSaver.saveAs(file, 'test.txt');
}, function (data) {
console.log("Download ERROR!");
console.log(data.status);
})
};
}])