Before using Angular.js's $http, I was testing the website's reactions with requests from the request module of node.js. My goal was to log in to a website with a POST request, take the cookie session and then download all the pages I wanted with requests with this cookie in their headers.
With Node.js, it looked like this :
request.post({url: myUrl/login.php, form:{login:'login', password:'password'}}, function(err, resp, body){
var cookies = parseCookies(resp) //function that takes all the cookies
request({url: myUrl/portail, headers{cookie: cookies}}, function(err, resp, body){console.log('recu')})
})
The response to post request is actually a redirection to myUrl/portail with 'set-cookie' in the headers
I would like to do this with my app using Angular.js, so I did this :
$http({
method: 'POST',
url: myUrl/login.php,
data: $.param({login: $scope.loginData.login, password: $scope.loginData.password}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(data, status, headers) {
var cookies = parseCookieAngularVersion(headers)
$http({
method:'GET',
url: myUrl/portail,
headers:{cookie:cookies}
})
.success(function(data, status, headers){
console.log(headers())
})
.error(function(){
console.log('ERRRROR')
})
})
.error(function(data, status, headers, config) {
console.log('ERRROR');
})
But it doesn't work... The headers don't contain any cookie and the server keeps send me the login page. The problem must be because AngularJs is a client-side application. Could someone helps me ? I would be very great. Thanks in advance