在Flutter网站中发生XMLHttpRequest错误时启用CORS [英] Enable CORS while an XMLHttpRequest error occurs in flutter web
本文介绍了在Flutter网站中发生XMLHttpRequest错误时启用CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用该函数将数据添加到数据库时,并且在服务器上添加了 Access-Control-Allow-Origin
,以便不会被CORS阻止,但是当我在浏览器控制台工具标签控制台中查看时仍会出错
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.
如何停用CORS?
推荐答案
用于在我的服务器上启用cors并解决波动网络中的 XMLHttpRequest错误
For enabling cors on my server and to resolve XMLHttpRequest error in flutter web
我正在使用此在我的 .htaccess
文件中,用于仅允许访问某些域
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>
这篇关于在Flutter网站中发生XMLHttpRequest错误时启用CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文