Reputation: 5618
I do not get why the following URL is not working. I am running a bunch of nearly identical requests successfully but this one is not arriving at the server. Could it be the URL length in ionic2 maxes out?
let requestURL = 'https://myServer/php/setUserPushInfo.php?user=user&PushToken=fc0112d3936f738d9d4c197c50abf80304ab13fca48b19d539ecacf65ce58b34&OS=iOS&other=value';
this.http.get(requestURL).map(res => {
console.log(JSON.stringify(res.json()));
return res.json();
},
err => {
console.log('ERROR ' + err);
}
);
similar requests in my code all the time. Using requestURL
in the browser works... ? There are 4 other requests to other php
files running concurrently and successfully.
Upvotes: 0
Views: 75
Reputation: 2081
Try it like this:
let requestURL = 'https://myServer/php/setUserPushInfo.php?user=user&PushToken=fc0112d3936f738d9d4c197c50abf80304ab13fca48b19d539ecacf65ce58b34&OS=iOS&other=value';
this.http.get(requestURL)
.map(res => res.json())
.subscribe(data => {
console.log("Data is :",data);
observer.next(data);
},
err => {
console.log('ERROR ',err);
observer.error(err);
});
Should work.
Upvotes: 0
Reputation: 29614
In Angular 2/Ionic 2, if you are using http module, the request itself is only sent if it is subscribed to by one or more subscribers. It uses Observables concept to make it work.
As soon as it has observers, it will send the request and return an observable for the response which will be later returned asynchronously. Without anything waiting for a response there is no need to send request.
Upvotes: 4