[前端][http]GET 请求也会存在跨域现象,但是 HTTP 状态为 200,依旧显示跨域

知识库问题地址open in new window

问题现象

Access to XMLHttpRequest at 'https://jd.spacecig.com/zhzlApi/event/v3/brain/shareFilePage' from origin 'http://localhost:8081' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

版本信息

M8

问题原因

请求存在跨域

排查步骤

关闭--disable-web-security  安全选项  ,可请求成功。

如何关闭--disable-web-security?

MAC OSX 系统

进入终端或者 iTerms
open -n /Applications/Google\ Chrome.app/ --args --disable-web-security --user-data-dir=/Users/kisn/Documents/MyChromeDevUserData

Window 系统

(1)新建一个 chrome 快捷方式,右键“属性”,“快捷方式”选项卡里选择“目标”,添加 --disable-web-security(1 图)

(2)新建一个 chrome 快捷方式,右键“属性”,“快捷方式”选项卡里选择“目标”,添加 --args --disable-web-security --user-data-dir

解决方案

这不能完美解决跨域问题,只是在 Chrome 端忽略了安全策略,最终解决还需要接口人员介入解决服务端跨域问题

最后更新时间::
贡献者: 吴松泽