CORS with Spring not working

混江龙づ霸主 提交于 2019-12-12 01:34:17

问题


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 ).

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.

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 ?


回答1:


My request to MongoDB looks like this one :

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

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 ;/



来源:https://stackoverflow.com/questions/14375505/cors-with-spring-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!