新版浏览器出现的跨域问题及解决方案
现象:
错误信息:
Access to XMLHttpRequest at ‘http://127.0.0.1:9581/GetInterface’ from origin ‘http://114.115.214.104:31102’ has been blocked by CORS policy: The request client is not a secure context and the resource is in more-private address space local.
错误原因:
新版的 Chromium 内核(可能是 93 或 94 版本)启用了新的安全策略,不再允许非 HTTPS 网站直接访问本地网络资源(CORS-RFC1918)
解决方案:
谷歌浏览器
步骤1: 谷歌浏览器 打开 chrome://flags/#block-insecure-private-network-requests
步骤2 : 找到 Block insecure private network requests. 设置为Disabled
步骤3 : 点击relaunch按钮重启谷歌浏览器,重新打开网页
edge浏览器
步骤1: 打开 edge://flags/#block-insecure-private-network-requests
步骤2 : 找到 Block insecure private network requests. 设置为Disabled
步骤3 : 点击relaunch按钮重启谷歌浏览器,重新打开网页