问题
when I will add data to the database using the function, and on the server I have added Access-Control-Allow-Origin
so that it is not blocked by CORS, but still error when I looked in the browser console tools tab console
Access to XMLHttpRequest at 'https://int.goo.id/api/pg/sso.register' from origin 'http://127.0.0.1:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
how to deactivate CORS??
回答1:
For enabling cors on my server and to resolve XMLHttpRequest error in flutter web
I am using this in my .htaccess
file for allowing access to certain domains only
<ifModule mod_headers.c>
SetEnvIf Origin "http(s)?://(localhost:25120|domain.com|domain2.com)$" AccessControlAllowOrigin=$0
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header always set Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
</ifModule>
回答2:
if you have experienced something like that, and the server has added Access-Control-Allow-Origin
but is still blocked by CORS, try checking the function (if you use the function to CRUD with postrgresql) because my problem is solved when I fix the function
回答3:
Disabling CORS policy on Chrome is a temporary solution. It's just frustrating that you have to manually call it before starting Chrome every. single. time. Disable same origin policy in Chrome
来源:https://stackoverflow.com/questions/57765054/enable-cors-while-an-xmlhttprequest-error-occurs-in-flutter-web