网站在调用访问者本地HTTP服务时遇到错误

错误结果:Failed to load resource: net::ERR_FAILED

错误信息:Access to XMLHttpRequest at 'http://127.0.0.1/xxxxx' from origin 'http://xxxxx.com' 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、最鸡肋的解决方法:更换使用旧版浏览器,或在新版浏览器修改对应的设置,如:edge://flags/#block-insecure-private-network-requests

2、最规范的解决方法:将站点迁移至 HTTPS 访问即可

3、最麻烦的解决方法:不要再使用此种访问方式,更换为其它业务逻辑。。。

 

参考来源:https://techcommunity.microsoft.com/t5/discussions/edge-beta-version-92-0-902-9-cors-error/m-p/2449176

https://stackoverflow.com/questions/66534759/chrome-cors-error-on-request-to-localhost-dev-server-from-remote-site

https://wicg.github.io/private-network-access/

posted @ 2021-09-29 18:35  不是豆豆  阅读(1027)  评论(0)    收藏  举报
友情链接:迷途