【问题标题】:CORS with Spring not working带有 Spring 的 CORS 不起作用
【发布时间】:2012-12-31 18:44:43
【问题描述】:

我的 Spring 应用程序中的 Access-Control-Allow-Origin 存在这个众所周知的问题。我使用跨域请求从内置 MongoDB 数据库 REST 接口(例如: http:\localhost:28017\db_name\collection_name )读取数据。

我的 javascript 客户端(JSONP 不起作用:()与此网页上的这个非常相似:http://2rdscreenretargeting.blogspot.com/2012/06/enable-cors-for-jersey.html。我还使用该网站上的 CORS 过滤器:http://software.dzhuvinov.com/cors-filter.html

我的 Spring 应用程序的每个响应在其标头中都有这个 Access-Control-Allow-Origin 属性,来自 mongodb 的响应除外。我还能做什么?

【问题讨论】:

  • 您能否验证 MongoDB 请求是否具有 Origin 标头?这就是触发 CORS 请求的原因。

标签: javascript spring mongodb cross-domain cors


【解决方案1】:

我对 MongoDB 的请求如下所示:

接受:/ 来源:本地主机:8080 引用者:localhost:8080/SpringHighcharts/chartmongo 用户代理:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17

我还发现 mongod 有参数 --json ,它允许通过 HTTP 接口访问 JSONP。在启用此选项之前考虑允许此活动的安全隐患,但即使启用此选项也不会改变我认为的任何内容;/

【讨论】:

    猜你喜欢
    • 2021-07-31
    • 2014-10-07
    • 1970-01-01
    • 2018-08-21
    • 2015-09-09
    • 1970-01-01
    • 2019-10-25
    相关资源
    最近更新 更多