My app is scraping data from a third party site wherein it needs to be logged in first before it could scrape the data. The thing is, there is a session expiration so the app needs to check if the session is already expired. If the session is not yet expired, $http's JSESSIONID cookie will be the same as the one returned after logging in. If it is expired, the value of JSESSIONID changes.
What I'm planning to do is that after logging in, I'll store the JSESSIONID to the localStorage. After every request of $http, I'll compare the new JSESSIONID to the stored JSESSIONID. I'll relogin the user if it's not the same(means session is expired).
However, I couldn't get the cookie. It returns undefined. I'm also thinking, is it because the cookie is on the request header instead of the response header? If yes, how could I get it?
$http({
method: 'POST',
url: url,
data: params
}).then(function (response) {
console.log($cookies.get('JSESSIONID'));
callback.success(Parser.getGrades(response.data));
}, function (error) {
callback.error();
});
I already included ngCookies, no errors but the value is undefined. I tried to use getAll() and it returns:
Object {_ga: "GA1.1.1725476839.1445841661"}
Configurations of my $httpProvider:
$httpProvider.defaults.withCredentials = true;
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';