如何處理使用 SAP UI5 消費真實的 OData 服務時遇到的跨域問題

我本地開發了一個 SAP UI5 應用,消費真實的 OData 服務:web

https://services.odata.org/No...sql

會遇到跨域問題錯誤:CORS error
chrome

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

相關文章
相關標籤/搜索