这里只说明访问本地api 问题,如果api已经是远程地址了,还出现跨域 那就是配置的有问题了 自行继续google
Access to XMLHttpRequest at ‘http://localhost:80/xxxxxxxx’ from origin
‘http://xxxxxxxxx’ has been blocked by CORS policy: The request client
is not a secure context and the resource is in more-private address
spacelocal
.
翻译过来就是:
一个外部请求访问到本地,已被CORS策略阻止:请求客户端不是一个安全的上下文,资源在更私有的地址空间“本地”。
人话就是:
网站访问你本地的api了 然后被浏览器拦了 (铐走…)
如果你就是要访问本地:
- 用Chrom的话
- 进chrome的设置中 chrome://flags/#block-insecure-private-network-requests
- 关掉 Block insecure private network requests. 也就是 设置为 Disabled
- WPF/WinForm 用的CefSharp
网上看到有说 设置这东西的 实测无效
settings.CefCommandLineArgs.Add("--disable-web-security", "");
最后是添加这个设置 (实测毛闷台)
settings.CefCommandLineArgs.Add("disable-features", "BlockInsecurePrivateNetworkRequests");
这一行代码加哪里 就看你自己的配置写哪在了
反正就是在下面这行之前 没写过的话 就 new CefSettings()
Cef.Initialize(settings);
最后还有一行代码建议添加 用处就是设置屏幕渲染最佳性能参数 包含禁用gpu等 具体的看代码实现
settings.SetOffScreenRenderingBestPerformanceArgs();
我用的版本