Cors issue in Ionic 5

I am newbie for Ionic. I am trying to post data using api through ionic. When I post data to a local file it is working But it could not post data to any external link.

Please suggest me any way so that I could resolve it.

The Ionic CLI introduced the ability to have a proxy server issue requests for you to get around anyCORS issues you may have. Since the server is sending a fresh request to your destination, there will be no origin and therefore, no CORS needed. It is important to note that the browser adds in the Origin header.
Here are detailed info about handling CORS issues in Ionic :https://docsbay.net/what-is-cors Hope it helps!

your external link have to include a Cross-Origin Resource Sharing (CORS) header in the response.
ex: @CrossOrigin in Spring Boot

Hi, Thanks for your replies. Is Proxy good idea to use for an application? I want to post and get response from external api . I am sharing the below code that I was trying. I am getting error “XHR failed loading: GET- https://my-json-server.typicode.com/typicode/demo/posts/” Please suggest me a right way.

First I tried this.

headers.append("Access-Control-Allow-Origin", '*');
				headers.append("Access-Control-Allow-Methods", 'POST, GET, OPTIONS, DELETE');
				headers.append('Content-Type', 'application/json' );
				let requestOptions 	= {headers: headers}
				this.httpClient.get('https://my-json-server.typicode.com/typicode/demo/posts/',requestOptions).subscribe(data => {
					console.log(data[0].title);
				   }, error => {
					console.log("error"+error);
				  });

Then I tried.

from(this.nativeHttp.get('https://my-json-server.typicode.com/typicode/demo/posts/', {}, {'Content-Type': 'application/json'})).pipe(
					  finalize(console.log("finalize"))
					).subscribe(data => {
					  console.log("success here");
					}, err => {
					  console.log("error"+err);
					});