CORS与春天不工作 [英] CORS with Spring not working

查看:340
本文介绍了CORS与春天不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have this well-known issue with Access-Control-Allow-Origin in my Spring application. I use cross-domain request to read data from built in MongoDB database REST interface (for example : http:\localhost:28017\db_name\collection_name ).

我的JavaScript客户端(JSONP does not work :()非常类似于此网页上的: http://2rdscreenretargeting.blogspot.com/2012/06/enable-cors-for-jersey.html 。请使用本网站的CORS过滤器: http://software.dzhuvinov.com/cors-filter.html

My javascript client (JSONP doesnt work :( ) is very similar to this one on this webpage : http://2rdscreenretargeting.blogspot.com/2012/06/enable-cors-for-jersey.html. I also use CORS Filter from this website : http://software.dzhuvinov.com/cors-filter.html.

我的Spring应用程序的每个响应都在这个Access-Control-Allow-Origin属性的头部,除了从mongodb的响应,我还能做什么?

Every response from my Spring app has in their header this Access-Control-Allow-Origin attribute, except response from mongodb. What else can i do ?

推荐答案

我对MongoDB的请求看起来像这样:

My request to MongoDB looks like this one :

strong>接受: /
原产地:localhost:8080
Referer:localhost:8080 / SpringHighcharts / chartmongo
User-Agent:Mozilla / 5.0(X11; Linux i686 )AppleWebKit / 537.17(KHTML,like Gecko)
Chrome / 24.0.1312.52 Safari / 537.17

Accept:/ Origin:localhost:8080 Referer:localhost:8080/SpringHighcharts/chartmongo User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17

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

I also found that mongod has parameter --json which Permits JSONP access via an HTTP interface. Consider the security implications of allowing this activity before enabling this option, but even enabling this option does not change anything i suppose ;/

这篇关于CORS与春天不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆