For info on Ionic and CORS, please read this very nice article. It explains exactly that testing with 'ionic serve' and 'ionic run -l' will trigger CORS. Running on the device will NOT trigger CORS checking. Really?
When I tried to perform in my Ionic Android app on my device (!) to access the html files of other sites, it still did not work. Hmmm.
How to solve this? You can use a proxy server to solve it. First I tried the next solution ... and it works - even for local testing!
https://cors-proxy.htmldriven.com/?url=http://www.example.com/page1
Next problem was ... can I create a very simple proxy server myself? Yes, and it is quite simple using Spring Boot. Just create a Controller that uses a simple OkHttp get call. This works even when testing using 'ionic serve'! This works when I configure Cors on the server in the right manner.
What about Ionic code? This is what worked for me (Ionic3/Angular5/HttpClient):
this.httpClient.get( url, { observe: 'body', responseType: 'text'}).subscribe(
data => {
console.log( 'Output is data = ' + data);
},
err => {
console.log( 'ERROR: ' + err.toLocaleString());
});
}
Yes, you need an own website faciliting this - that being the downside. It will also take an extra internet 'stop' to get you remote HTML stuff.