# Cors issue in Ionic 5

**URL:** <https://forum.ionicframework.com/t/cors-issue-in-ionic-5/168963>\
**Category:** Ionic Framework\
**Created:** [July 17, 2019, 7:26pm UTC](https://forum.ionicframework.com/t/cors-issue-in-ionic-5/168963 "2019-07-17T19:26:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mackiconicappp](https://avatars.discourse-cdn.com/v4/letter/m/cc9497/32.png) [@mackiconicappp](https://forum.ionicframework.com/u/mackiconicappp)\
**Post date:** [July 17, 2019, 7:26pm UTC](https://forum.ionicframework.com/t/cors-issue-in-ionic-5/168963/1 "2019-07-17T19:26:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TimLavagi](https://avatars.discourse-cdn.com/v4/letter/t/7c8e57/32.png) [@TimLavagi](https://forum.ionicframework.com/u/TimLavagi)\
**Post date:** [July 18, 2019, 1:45am UTC](https://forum.ionicframework.com/t/cors-issue-in-ionic-5/168963/2 "2019-07-18T01:45:08Z")

</div>

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](https://docsbay.net/what-is-cors) Hope it helps！

---

<div class="post-metadata">

**Author:** ![Tobias1](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@Tobias1](https://forum.ionicframework.com/u/Tobias1)\
**Post date:** [July 18, 2019, 9:56am UTC](https://forum.ionicframework.com/t/cors-issue-in-ionic-5/168963/3 "2019-07-18T09:56:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mackiconicappp](https://avatars.discourse-cdn.com/v4/letter/m/cc9497/32.png) [@mackiconicappp](https://forum.ionicframework.com/u/mackiconicappp)\
**Post date:** [July 20, 2019, 3:32am UTC](https://forum.ionicframework.com/t/cors-issue-in-ionic-5/168963/4 "2019-07-20T03:32:56Z")

</div>

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/](https://my-json-server.typicode.com/typicode/demo/posts/)” Please suggest me a right way.

First I tried this.

```auto
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.

```auto
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);
					});

```
