0

I am trying to get data from an API from the internet, using Angular version 16, I tried everything but I still get the CORS error saying "Access to XMLHttpRequest at 'http://www.travel-advisory.info/api' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request." Here is the internet.service.ts file enter image description here Also I don't really know how to implement the Headers, I tried a few codes but didn't change anything

Here is also the proxy.config.json file I created based on research , I also configure the angular.json file and put up },enter image description here "serve": {

      "builder": "@angular-devkit/build-angular:dev-server",
      "configurations": {
        "production": {
          "browserTarget": "move-safe:build",
          "proxyConfig": "src/proxy.config.json"
        },

        "development": {
  • It's no good creating a proxy if you don't change the URLs you are using to point to the proxy instead of to the original site. – Quentin May 08 '23 at 21:23
  • Could you tell me how to do it? Examples I found are using localhost apps,my api goes to a page on the internet – Eliana Maria May 09 '23 at 03:00
  • Most likely a change is needed in your backend, you need to allow CORS along with all the methods you are using. If you are using spring, you might need to look how this is done in the spring security – Alexander Mladzhov May 09 '23 at 11:33
  • @ElianaMaria — You have some code (which you haven't shared with us) which tries to make a request to `http://www.travel-advisory.info/api` and you need to change that so it makes a request to the URL of the proxy server you created. – Quentin May 09 '23 at 18:57

0 Answers0