我本地开发了一个 SAP UI5 应用,消费真实的 OData 服务:web
https://services.odata.org/No...sql
会遇到跨域问题错误:CORS errorchrome
Access to XMLHttpRequest at ' https://services.odata.org/No... from origin ' http://localhost:3002' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
由于 https://services.odata.org/No... 这个 OData 服务不是咱们自行实现的,咱们没法更改其实现端,添加 CORS policy 相关的协议字段,所以只能想其余办法。跨域
出于开发目的,咱们能够暂时禁掉 Chrome 的安全检查,来绕过这个错误。安全
新建一个批处理文件,输入下列内容:spa
cd C:\Program Files (x86)\Google\Chrome\Application chrome.exe --user-data-dir="C:/temp" --disable-web-security
此时启动的 Chrome,会显示一行警告信息:code
You are using an unsupported command-line flag: --disable-web-security. Stability and security will suffer.开发
此时请求 OData 元数据,再也不有跨域错误了:rem
更多Jerry的原创文章,尽在:"汪子熙":get