Ionic Native HTTP returns {status: -1} for a single API call in IOS Simulator
I'm using Ionic Native HTTP to get around CORS issues in IOS and there's a single Wordpress API call /wp-json/wp/v2/ that is always returning -1, despite the fact that other /wp-json/wp/v2/ api calls work perfectly fine.
In addition, this works fine in Android, it's just IOS that's having issues.
HTTP Code where http = @ionic-native/http/ngx
const url = https://example.com/wp-json/wp/v2/data?order=asc&order_by=id&per_page=100&after=2020-07-30 00:00:00&before=2020-07-30 23:59:59;
this.http.get(url, {}, {})
.then((data) => {
console.log('returning data');
console.log(data);
})
.catch((err) => {
console.log('erroring');
console.log(err);
console.log(err.status);
console.log(err.error); // error message as string
console.log(err.headers);
});
There's nothing special about this code, it's just a single Wordpress API call, but I always get -1 returned. This question states it's a CORS issues, where pre-flight OPTIONS requests get rejected, but the entire point of Native HTTP was to avoid CORS as I cannot modify the server.
Has anyone else encountered and fixed this status -1 issue?
EDIT See my answer below.
The issue was the space in the URL, it seems that Android and browsers automatically replace the space with %20, but IOS does not.
Thus the new URL should be as below and that now works fine.