CORS Error in ionic

hi i am trying to post the data to another domain using $http.post i found the cors error in my console. But the cors was enabled on both sides. can any one help me out how to fix this problem and how to post the data to different server without cors issue. i am using ubuntu and i am getting two errors here

The error is
1.OPTIONS http://somedomain/api/login 404 (Not Found)

2.XMLHttpRequest cannot load http://somedomain/api/login. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost’ is therefore not allowed access.

Here is something that helped me :smile:

Answer here: Making REST call from Ionic

You can use the Ionic proxy feature to get around CORS while you develop. This does not solve it for production apps though, since they won’t be running with ionic serve.

http://ionicinaction.com/how-to-fix-cors-issues-revisited/

Hi better to add ‘Access-Control-Allow-Origin:*’ extension to Google Chrome
then We can solve CORS error

1 Like

During testing locally, this is an easy win - props!

I have problem

in ionic serve cors is working in browser but not working apk

. In the browser (using ionic serve) it was working properly , but in apk (using ionic build android ) it was not working…

cordova plugin add cordova-plugin-whitelist (I have added this puigin using CLI)

I have used these things in config.xml

ionic.project
{
“name”: “sampleApp”,
“app_id”: “a2fbab8f”,
“proxies”: [
{
“path”: “/api”,
“proxyUrl”: “http://myserver/api
}
]
}