0

I am using $http.post() to access an api but I get the response back

XMLHttpRequest cannot load http://tester.com/cp/api/index.php?action=1. Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.

And I have added <?php header('Access-Control-Allow-Origin: *'); ?> to the index.php.

I don't know why it is not working.

Insane Skull
  • 9,220
  • 9
  • 44
  • 63
  • See this http://stackoverflow.com/questions/25727306/request-header-field-access-control-allow-headers-is-not-allowed-by-access-contr . You can also for development install chrome plugin `Allow-Control-Allow-Origin` – Olga Akhmetova Jan 27 '16 at 08:56

1 Answers1

0

Create a proxy service running on the top of NodeJS by executing these line in your console:

npm install -g corsproxy

Then simply start the proxy with:

corsproxy

It will ask you where/on which port do you want to run it. Choose something and it will output something like (in my case was that):

http://localhost:8100/

Then you will be able to make requests like:

http://localhost:8100/yourdomain.com/api/endpoint

Remember the 'CORS problem' persists only on your local machine's browser and therefore there is no need for CORSPROXY when you make API calls from the mobile device.

Read more about it here: http://ionicinaction.com/blog/how-to-fix-cors-problems-and-no-access-control-allow-origin-header-errors-with-ionic/

radioaktiv
  • 2,437
  • 4
  • 27
  • 36