【发布时间】:2014-01-20 22:12:59
【问题描述】:
我已经能够使用此 URL 并通过适当的身份验证从 liferay 网络服务访问 json 数据:
http://login:password@localhost:8080/tunnel-web/secure/json
但我需要从另一个域名的 javascript 中查询这个。
我遇到了经典错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://my.origin.com/' is therefore not allowed access.
我知道我必须在服务器响应标头上允许这个来源,这可以在 jsp 中像这样完成:
response.setHeader("Access-Control-Allow-Origin", "http://my.origin.com");
问题是,我怎样才能允许 liferay 的默认 web 服务使用这个来源?
编辑:
我尝试添加一个 portal-ext.properties 文件:
axis.servlet.hosts.allowed=
axis.servlet.https.required=false
tunnel.servlet.hosts.allowed=
tunnel.servlet.https.required=false
//empty values are meant to allow any IP...
但这并没有改变任何东西:(
PS:我正在使用 liferay 6.06
【问题讨论】:
-
你用什么来提出请求? AlloyUI 还是 jquery?
-
我正在使用 jquery。不过没关系,也可以从纯javascript调用,标准XMLHttpRequest对象没有?
-
试试这个
response.setHeader("Access-Control-Allow-Origin", "*");然后告诉我 -
问题是,我不知道哪个文件正在发送响应,因为我点击了“tunnel-web”地址,所以我不知道在哪里设置这个标头:/
-
如果liferay前面有apache web server(或类似的),可以在proxy pass rules中设置response header..
标签: javascript web-services cross-domain liferay liferay-6