这个错误是 Content Security Policy (CSP) 导致的。CSP 是一种安全机制,限制网页能加载的资源,以防止 XSS(跨站脚本攻击)等安全威胁。
错误原因
你的网页的 CSP 规则中,connect-src 或 default-src 没有允许访问 https://。。。。。.cn/service_auth/login,因此浏览器阻止了请求。
开发tauri程序的肯定都遇到过这个错误提示:
Refused to connect to ******* because it appears in neither the connect-src directive nor the default-src directive of the Content Security Policy.
这是因为你的请求或者资源被tauri的内容安全策略拦截了
看官方文档:Configuration | Tauri
想要彻底解决这个错误提示也很简单,有两种方法。一个是将你的资源请求域加入csp中,但是这种有点麻烦:
还有一种就是一劳永逸,彻底关闭这个安全限制:
"security": {
"csp": null,
"dangerousDisableAssetCspModification": true,
"assetProtocol": {
"enable": true,
"scope": {
"allow": ["**/*"],
"requireLiteralLeadingDot": false
}
}
}
关闭之后,就再也不用担心了