文章目录
1.前置参考
https://www.cnblogs.com/songfengyang/p/15627408.html
2.chrome浏览器设置允许跨域
2.1新版block-insecure-private-network-requests设置已被移除
老版本chrome设置允许跨域设置chrome://flags/#block-insecure-private-network-requests,将其设置为Disabled的选项在新版的chrome中没有该选项。
2.2跨域正确姿势
新版的跨域设置需要设置浏览器启动参数:
--args --disable-web-security --user-data-dir=D:\MyChromeDevUserData2
这个我试过了,有效的。
java后端项目跨域正确姿势:
https://mp.weixin.qq.com/s/tbqjCKrTMj-l1lZbeyu81g
https://blog.csdn.net/qq_34905631/article/details/156759710?spm=1001.2014.3001.5501
3.新版安全网络限制
新版本会有一个专有或本地网络的安全限制默认是开启的,是为了防止跨站请求伪造 (CSRF) 攻击,所以可以设置:
chrome://flags#local-network-access-check 设置为Disabled
或者设置浏览器启动参数:
--enable-features=PrivateNetworkAccessRespectPreflightResults 绕过私有网络安全限制
这个我试过了,有效的。
页面就可以访问私有网络ip,后端请求头返回,且Access-Control-Allow-Origin限制允许的域
Access-Control-Request-Private-Network: true
Access-Control-Allow-Origin: xxxxxxxx(返回具体允许的域,而不是*)
4.参看官方说明
https://developer.chrome.google.cn/blog/local-network-access?hl=zh_cn
https://developer.chrome.com/blog/private-network-access-preflight?hl=zh-cn