Response to preflight request doesn't pass access control check

后端 未结 21 2221
别那么骄傲
别那么骄傲 2020-11-22 03:50

I\'m getting this error using ngResource to call a REST API on Amazon Web Services:

XMLHttpRequest cannot load http://server.apiurl.com:8000/s/login

21条回答
  •  -上瘾入骨i
    2020-11-22 04:24

    JavaScript XMLHttpRequest and Fetch follow the same-origin policy. So, a web application using XMLHttpRequest or Fetch could only make HTTP requests to its own domain.

    Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

    You have to send the Access-Control-Allow-Origin: * HTTP header from your server side.

    If you are using Apache as your HTTP server then you can add it to your Apache configuration file like this:

    
        Header set Access-Control-Allow-Origin "*"
    
    

    Mod_headers is enabled by default in Apache, however, you may want to ensure it's enabled by running:

     a2enmod headers
    

提交回复
热议问题