You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cognos Mashup Service外部浏览器访问出现CORS跨域错误求助

解决Cognos Mashup Service(CMS)跨域(CORS)访问错误

Hey there, I’ve helped other developers troubleshoot exactly this CORS issue with Cognos Mashup Service, so let’s break down the fixes tailored to your scenario:

1. 给Cognos服务器配置CORS允许规则(生产环境推荐)

这是最彻底的解决方式,需要在Cognos服务器端添加跨域支持:

  • 找到你的Cognos安装路径下的webapps/p2pd/WEB-INF/web.xml文件
  • 在现有过滤器配置之前,插入以下CORS过滤器代码(记得替换cors.allowed.origins的值为你Eclipse应用运行的实际地址,比如http://localhost:8080):
<filter>
    <filter-name>CORSFilter</filter-name>
    <filter-class>com.ibm.cognos.cgi.CORSFilter</filter-class>
    <init-param>
        <param-name>cors.allowed.origins</param-name>
        <param-value>http://localhost:8080</param-value>
    </init-param>
    <init-param>
        <param-name>cors.allowed.methods</param-name>
        <param-value>GET,POST,PUT,DELETE,OPTIONS</param-value>
    </init-param>
    <init-param>
        <param-name>cors.allowed.headers</param-name>
        <param-value>Content-Type,Authorization,X-Requested-With</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>CORSFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
  • 保存文件后重启Cognos服务,新的跨域规则就会生效了

2. 用Eclipse服务器做请求转发(开发环境便捷方案)

如果不想动Cognos的服务器配置,你可以让Eclipse的应用服务器做代理,把Cognos请求转发过去,这样浏览器会认为所有请求都来自同一源:

  • 打开Eclipse的Window > Preferences > Server > Runtime Environments,找到你用的应用服务器(比如Tomcat)
  • 配置代理规则:把Cognos的请求路径(比如/bi/v1/disp)映射到你的Cognos服务器地址(比如http://your-cognos-server:9300/bi/v1/disp)
  • 重启应用服务器,之后通过Eclipse的服务器地址访问CMS,外部浏览器就不会触发跨域错误了

3. 临时禁用浏览器同源策略(仅开发测试用!)

要是你只是想快速验证功能,不想改任何配置,可以给浏览器加启动参数关闭CORS检查,但绝对不能在生产环境用:

  • Chrome:右键点击Chrome快捷方式 → 属性,在目标栏末尾加 --disable-web-security --user-data-dir="C:/ChromeDevSession"(注意前面有空格),然后启动Chrome
  • Firefox:在地址栏输入about:config,搜索security.fileuri.strict_origin_policy,把它改成false

提醒:这种方法会降低浏览器的安全性,只适合本地开发测试时临时用


内容的提问来源于stack exchange,提问作者Joshua Knight

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:12:07