CORS – Cross-Origin Resource Sharing
Cross-Origin Resource Sharing (CORS) is a mechanism that uses additional HTTP headers to tell a browser to let a web application running at one origin (domain) have permission to access selected resources from a server at a different origin.
If you are not that familiar with CORS read about CORS first then continue with this article.
Angular runs on its own server (by default localhost:4200) and webAPI runs on a different port so we get the Cors issue.

So, from the above screen, it is clear that WebAPI is running on port 57263 and our application is running on 4599 (it's not running in 4200 as I have changed the port in package.json).
http://localhost:4599 - http://localhost:57263 (here domain is same but the port number is different - one of the rules to satisfy CORS)
So, the solution for the above issue is,
- Angular proxy (client-side solution)
- Enable CORS on the webAPI (Server Side)
In this article, we will see a detailed explanation on how to use Angular Proxy only. This example is created using Angular CLI version 6.
Step 0

Step 2
Step 3
Here, only the structure and code snippets are shown, you can put it together for a proxy shows.
Project structure




tejaswi pandavaPosted Mar 29, 2021, 8:58 AM
Can you please attach the source code for this project it would be a really great.
venkatesh cPosted Jun 22, 2020, 5:18 AM
Thanks, its working for me
Adel TabarehPosted Dec 24, 2019, 3:03 AM
Thanks. a little point for those who cannot make it working for the url outside localhost is to add "changeOrigin": true according to https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/proxy.md
mehmet dilmenPosted Aug 22, 2019, 4:00 AM
When I refresh the page, page leading to beckend API link. How can i fix it. Thanks
GWEN ZHOUPosted Jul 26, 2019, 9:49 AM
Super helpful, thanks
veera kallamPosted Jun 11, 2019, 2:35 AM
Thanks.It worked for localhost.How to do for production?
Kate CatalenaPosted Jun 10, 2019, 3:37 PM
This is a very helpful tutorial. I was wondering about when you are trying to use this with an external API. I tried following all the steps and just using the external api, but I had no luck I get a connection refused error. The external api I am trying to access is an https site and requires some headers which I have also incorporated. Any ideas what I might could try?
shiva kumarPosted May 3, 2019, 1:32 AM
Really Ur superb solved cors issue