Here is my code:
$http({
method: 'POST',
url: myURL,
headers: {
//BLAH
},
data: {
// BLAH BLAH
}
}).success(function(data, status, headers) {
deferred.resolve({
// This is not possible:
sessionId: headers('sessionId')
});
});
I would like to access sessionId attribute from headers, but only header I seem to find is Content-Type.
What may be the cause why this does not work?
I found this post useful: https://github.com/mgonto/restangular/issues/128
It states the following:
After research I found the solution: you have to tell your api server to "expose" the custom headers. You can do this by using the
Access-Control-Expose-Headers
header. The value is the headers you want to be able to access. So it'd look like:Access-Control-Expose-Headers: Your-Header, Another-Header
.
Adding this extra header solved my problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.