I tried to login a third party forum, it returns response with set-cookie headers like
Set-Cookie: EeqY_2132_sid=JxX6CY; expires=Thu, 26-Jan-2017 01:55:07 GMT; path=/
Set-Cookie: EeqY_2132_lastact=1485309307%09member.php%09logging; expires=Thu, 26-Jan-2017 01:55:07 GMT; path=/
Set-Cookie: EeqY_2132_sid=JxX6CY; expires=Thu, 26-Jan-2017 01:55:07 GMT; path=/
native HTTP only get one of them in response.headers[‘Set-Cookie’]
import { HTTP } from 'ionic-native'
....
HTTP.get (url, {}, {}).then( response => {
alert(response.header['Set-Cookie']);
}
it alerts, say, ’ EeqY_2132_sid=JxX6CY; expires=Thu, 26-Jan-2017 01:55:07 GMT; path=/’, and that’s all
I’m not sure this is relevant, but is there a specific reason you’re using this instead of the Http
service from @angular/http
?
No specific reasons. I’m new to Ionic, so I just followed a turorial using native HTTP. Is there any diffences between them?
They’re vastly different. Chances are you do not need to use the ionic native http, and can use the @angular/http
library.
I tried angular http, but it didn’t work, said ‘Response with status: 0 for URL: null’. I ran it on my phone
I can see the request and response in Charles. Is it CORS problem?
but it showed status 200 for “https://httpbin.org/ip ”
buttonTapped(event: any) {
this.http.get(someurl).subscribe(data => {
alert(data);
}, error => { alert(error); });
}
That “URL: null” looks fishy. Are you sure that someurl
is properly set at the time you are using it?
YakuRyu
January 29, 2017, 11:05am
7
I tried several different sites, only the one returning json gives status 200 (https://httpbin.org/ip )
@YakuRyu
you can use angular2 -cookie
npm install angular2-cookie
here is the reference to get all cookies