I'm working on a app based on AngularJS. I would like to load some contents
that are available on a web site server. On a web browser, it uses a really
basic form to login. I test how the server reacts with a nodeJS server
using request module and succeeded to load what I wanted. Now I would like
to do this with AngularJS.
I have to :
-
create a post request which contains the form. The server would answer
with a request containing a redirection to the urlPortail and a set-cookie.
-
block this redirection or at least put the cookie asked to the headers
of the redirection request
-
put this cookie to new requests to load the content I want
In Node.js :
request = require('request')
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')})
})
What I writed with Angular.js :
$http({
method: 'POST',
url: 'url/login.php',
data: $.param({login: 'login', password: 'password'}),
headers: {'Content-Type':
'application/x-www-form-urlencoded'}}).success(function(data1, status,
headers1) {
console.log('headers 1')
console.log(headers1())
var session = parseCookies(headers1()); //Create a string (something like
'id=12jkl23244') with set-cookie of the headers
$http({
method : 'GET',
url: 'url/urlIWant',
headers: {cookie: session}
})
.success(function(data2, status, headers2){
console.log(data2)
})
This code doesn't work.
data1 contains the html of 'login.php' as if AngularJS made the redirection
to 'urlPortail' without putting the cookie session of set-cookie (so the
server doesn't know who I am and answers with the default page 'login.php')
or worse, this stratagem to put a form in a request doesn't work.
data2 also contains the html of 'login.php'.
I'm blocking on this for a really really long time. I heard about $cookies
and $storeCookies but I'm not understanding well what they do. Especially
as they seem to work with the browser whereas I'm looking to put all this
AngularJS stuff to an Ionic project,which is a framework to create hybrid
Mobile Apps.
Hope you could help me. All comments are welcome. Thanks in advance.
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.