javascript - AngularJS, get cookie session from a post response to get access to user contents on another web site -
i'm working on app based on angularjs. load contents available on web site server. on web browser, uses basic form login. test how server reacts nodejs server using request module , succeeded load wanted. angularjs.
i have :
create post request contains form. server answer request containing redirection urlportail , set-cookie.
block redirection or @ least put cookie asked headers of redirection request
put cookie new requests load content want
what writed :
$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 string (something 'id=12jkl23244') set-cookie of 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 html of 'login.php' if angularjs made redirection 'urlportail' without putting cookie session of set-cookie (so server doesn't know , answers default page 'login.php') or worse, stratagem put form in request doesn't work.
data2 contains html of 'login.php'.
i'm blocking on really long time. heard $cookies , $storecookies i'm not understanding do. seem work browser whereas i'm looking put angularjs stuff ionic project,which framework create hybrid mobile apps.
hope me. comments welcome. in advance.
i found answer several days later. handles alone. have put requests in right order , cookies automatically managed.
Comments
Post a Comment