網站在調用訪問者本地HTTP服務時遇到錯誤


錯誤結果:Failed to load resource: net::ERR_FAILED

錯誤信息:Access to XMLHttpRequest at 'http://127.0.0.1/xxxxx' from origin 'http://xxxxx.com' has been blocked by CORS policy: The request client is not a secure context and the resource is in more-private address space `local`.

錯誤原因:新版的 Chromium 內核(可能是 93 或 94 版本)啟用了新的安全策略,不再允許非 HTTPS 網站直接訪問本地網絡資源(CORS-RFC1918)

 

解決方案:

1、最雞肋的解決方法:更換使用舊版瀏覽器,或在新版瀏覽器修改對應的設置,如:edge://flags/#block-insecure-private-network-requests

2、最規范的解決方法:將站點遷移至 HTTPS 訪問即可

3、最麻煩的解決方法:不要再使用此種訪問方式,更換為其它業務邏輯。。。

 

參考來源:https://techcommunity.microsoft.com/t5/discussions/edge-beta-version-92-0-902-9-cors-error/m-p/2449176

https://stackoverflow.com/questions/66534759/chrome-cors-error-on-request-to-localhost-dev-server-from-remote-site

https://wicg.github.io/private-network-access/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM